Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a feature class and using arcpy.da.SearchCursor I'm getting unique values of a field (e.g. Name). How can I use this method to get the associated row value of a different field (diff field = Name2)?

So far I use this to get unique values on only field Name:

values = [row[0] for row in arcpy.da.SearchCursor(fc, ("Name"))]
    uniqueValues = set(values)
    for value in uniqueValues:  

When searching through the feature class how do I also get the value of another field, field Name2?

share|improve this question
Can you provide a little more context? What are you looking to do exactly? – blah238 Feb 4 '13 at 20:46
up vote 7 down vote accepted

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")):
share|improve this answer

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.

share|improve this answer
@con, The list of fields .format row method did not work for, for value in uniqueValues: – artwork21 Feb 5 '13 at 15:20
@artwork21 Can you post the modified code as an edit to your additional question? – Fezter Feb 6 '13 at 4:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.