Getting unique value of second field using arcpy.da.SearchCursor?

Dictionary comprehension:

{row[0]: row[1] for row in arcpy.da.SearchCursor(fc, ("Name", "Name2"))}

Note this will only have ONE value per unique Name column value. You can also use collections to get a list of Name2 values:

import collections
names = collections.defaultdict(list)

for name1, name2 in arcpy.da.SearchCursor(fc, ("Name", "Name2")):
    names[name1].append(name2)

The help file on SearchCursor (arcpy.da) has Code Samples at the bottom. The first SearchCursor example 1 shows how to grab a list of fields. Assign the row[0] and row[1] to variable names to use in your code.

Tags:

Cursor

Arcpy