# Create dictionary with segmentid as key, calculated length as value1, measured length as value2 fiberCableLengths = defaultdict(list) with arcpy.da.SearchCursor(fiberCable, ['segmentid', 'calculatedlength', 'measuredlength']) as cursor: for row in cursor: fiberCableLengths[row[0]].append(row[1]) fiberCableLengths[row[0]].append(row[2]) # Create slackloop dictionary with segmentidfkey as key, total up the length values of each slackloop under that segmentidfkey, and store as the dictionary value slackloopLengths = defaultdict(list) with arcpy.da.SearchCursor(slackLoop, ['segmentidfkey', 'length']) as cursor: for row in cursor: if row[1] is not None: slackloopLengths[row[0]].append(row[1]) # For each fibercable segmentid in dictionary, If calculated length + total slackloop length = measured length – Add to good list, Else – Add to bad list goodList = [] badList = [] with arcpy.da.SearchCursor(fiberCable, ['segmentid', 'calculatedlength', 'measuredlength']) as cursor: for row in cursor: if row[1] + slackloopLengths[1] == row[2]: goodList.append[row[1]] else badList.append[row[1]]
The code above creates a dictionary where each item looks like the following:
'1f169eae-5d7c-4ebb-90cd-abbe0e1b72dd': [50.0, 50.0, 50.0, 50.0]
How do I get it to sum the values for each key? The output I'd be looking for here would be:
4ebb-90cd-abbe0e1b72dd': [200]
Resources I've looked at:
https://stackoverflow.com/questions/4880960/how-to-sum-all-the-values-in-a-dictionary/4881100 https://stackoverflow.com/questions/34849651/how-to-add-the-values-of-dictionary-with-same-keys-in-python https://stackoverflow.com/questions/34849651/how-to-add-the-values-of-dictionary-with-same-keys-in-python