Skip to content

Instantly share code, notes, and snippets.

@knu2xs
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knu2xs/8721712 to your computer and use it in GitHub Desktop.
Save knu2xs/8721712 to your computer and use it in GitHub Desktop.
This is a Python function returning unique values from a field in an ArcGIS table, either a stand alone table or a feature class. It was adapted from code sample on ArcGIS resource center Help documentation on arcpy.da.SearchCursor http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000011000000
# Depends on first importing arcpy.da at top of script
def unique_values(input_table, field):
# search cursor wrapped in list generator creating list of all values
values = (row[0] for row in arcpy.da.SearchCursor(input_table, (field)))
# pass list into set to get only unique values and return the result
return sorted(set(values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment