Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created December 18, 2018 14:33
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 maptastik/13f361d4cfa3d90586af56b610675fdd to your computer and use it in GitHub Desktop.
Save maptastik/13f361d4cfa3d90586af56b610675fdd to your computer and use it in GitHub Desktop.
""" Generate a list of unique values for a field in a feature class
Parameters:
fc (str): Input feature class
field (str): Field to find unique values for
Returns:
list: unique values in a field
"""
def uniqueVals(fc, field):
valsList = []
with arcpy.da.SearchCursor(fc, field) as cursor:
for row in cursor:
if row[0] not in valsList:
valsList.append(row[0])
if None in valsList:
valsList.remove(None)
valsList.sort()
return valsList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment