Somehow I'm not able to add all values in a search cursor to a dictionary - one value pair is missing? What is my mistake?
def Dict1(self):
with arcpy.da.SearchCursor(outIntersect, ["FID_Anbinden1", "FLURSTUECKSTEXT"]) as cursor:
for row in cursor:
print("{} - {}".format(row[0], row[1]))
myKey = row[1]
myValue = row[0]
myDict[myKey] = myValue
# myDict.update({myKey: myValue})
print myDict
This leads to this output (as well as .update in line 9):
1 - 10125
1 - 10079
1 - 10337/2
2 - 10125
{u'10079': 1, u'10337/2': 1, u'10125': 2}
u'10125':1 is missing?
Solved! Go to Solution.
Your keys have to be unique. The key: value pair "10125: 1" is getting overwritten by the pair "10125: 2"
Your keys have to be unique. The key: value pair "10125: 1" is getting overwritten by the pair "10125: 2"
Thank you ...
If you need to have multiple values for each key, then use a list rather than a value, like "10125: [1,2]"
See this post: python - Adding new key to dictionary overwrites all previously stored keys with new keys values - S...
Ah ok, will try to use a list.