Filling dictionary with list of row attributes using arcpy.SearchCursor
Consider using an arcpy.da.SearchCursor:
FieldNameDict = {}
with arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN']) as rows:
for row in rows:
FieldNameDict[row[0]] = row[1:] # everything but the first element
As the row is a tuple that is returned you can use simple indexing [1:]
to return everything in the row after the first element (row[0]
) and clean up the cursor, releasing locks, when done. Be aware though that if the values of myfield
aren't unique the value stored against the key of the preexistent will be overwritten.
I have not tested this but it is a one liner that uses dictionary comprehension, an arcpy.da.SearchCursor()
and the indexing syntax from the answer by @MichaelStimson:
FieldNameDict = {row[0]:[row[1:]] for row in arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN'])}