import arcpy fiberCable = r'C:\Users\broadhurstn\Documents\ArcGIS\Default.gdb\FIBERCABLE' fibercableToConduit = r'C:\Users\broadhurstn\Documents\ArcGIS\Default.gdb\FibercableToConduit' conduit = r'C:\Users\broadhurstn\Documents\ArcGIS\Default.gdb\CONDUIT' # Populate a dictionary that maps segment ID to the placed/planned date segment_dates = {} with arcpy.da.SearchCursor(fiberCable, ['segmentid', 'bv_cable_placed_planned']) as cursor: for row in cursor: segment_dates[row[0]] = row[1] # Populate a dictionary that maps conduit ID to a two-item list containing segment ID and placed/planned date ftcs = {} with arcpy.da.SearchCursor(fibercableToConduit, ['conduitipid', 'segmentid']) as cursor: for row in cursor: # Use .get() so that it won't fail if a segment ID isn't in the dictionary ftcs[row[0]] = [row[1], segment_dates.get(row[1])] # Populate conduit 'bv_placed_est' field with arcpy.da.UpdateCursor(conduit, ['ipid', 'bv_placed_est_1']) as cursor: for row in cursor: for k, v in ftcs.items(): if row[0] == k: row[1] = str(v[1]) cursor.updateRow(row)
The above code and feature class table produce a dictionary that fills as follows:
{'daac02d0-bf62-4968-b1cd-0fe36c391b2f': ['55a16ddd-2d1d-443b-9935-ecafd2bc7d3b']
How do I add a second value to the dictionary using the below feature class table?
Notice how the value in the dictionary matches "segment ID" in this feature class. I want to have the the SearchCursor look at the current dictionary, see if there is a value that matches the "SegmentID" field values and append the field "Cable Placed Planned" to it's corresponding dictionary item as a second value.
Expected output for the first item:
{'daac02d0-bf62-4968-b1cd-0fe36c391b2f': ['55a16ddd-2d1d-443b-9935-ecafd2bc7d3b', '3/28/2020']
What I've created so far, which doesn't work correctly:
with arcpy.da.SearchCursor(FIBERCABLE, ['segmentid', 'bv_cable_placed_planned']) as cursor: for row in cursor: if FTCDICT[str(row[0])] == str(row[0]): FTCDICT[str(row[1])] = str(row[1])