Last active
August 1, 2016 07:20
-
-
Save M-Bryant/ece669ce3726b45774ea27405ebb90f3 to your computer and use it in GitHub Desktop.
arcpy: Sort a separated value into an order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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