Skip to content

Instantly share code, notes, and snippets.

@M-Bryant
Last active August 1, 2016 07:20
Show Gist options
  • Save M-Bryant/ece669ce3726b45774ea27405ebb90f3 to your computer and use it in GitHub Desktop.
Save M-Bryant/ece669ce3726b45774ea27405ebb90f3 to your computer and use it in GitHub Desktop.
arcpy: Sort a separated value into an order
def sortValues(the_value, delimiter=','):
"""Sort a separated value into an order
Useful to run on ArcGIS processes where there is no control on returned values.
For example SpatialJoin, JOIN_ONE_TO_ONE, with FieldMapping Merge Rule = Join
"""
if the_value == None:
return the_value
# Create a Python list by splitting the string on the delimeter
the_list = the_value.split(delimiter)
# Sort the list
the_list.sort()
# Reassemble the string from the sorted list
rval = delimiter.join(the_list)
return rval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment