Create List of Unique Table Values using Data Access Module
A while back I posted a slightly more verbose solution for this. Since then two things have changed. First, I have used Python a LOT more and understand how to use sets, lists and functions a little better. Second, the data access module has been added to ArcPy. The data access module cursors are much faster than the old cursors and also allow for field filtering, meaning Python does not have to load the entire table when searching. This updated version takes advantage of this. If you are using this functionality with large datasets, this updated version may be a little faster and save you some time processing.
# Return list all permutations of field in input feature class or table
def getValueList (inputTable, field):
valueSet = set() # set to hold unique values
# use data access search cursor combined with, 'with'
with arcpy.da.SearchCursor(inputTable, field) as values:
# iterate through all values returned by Search Cursor
for value in values:
# Add value to set. If the value is not present,
# it will be added. If it is present, the set will not
# allow duplicates.
valueSet.add(value[0])
# sort and return list of values
return sorted(valueSet)