Created
August 2, 2013 21:00
-
-
Save deanohyeah/6143422 to your computer and use it in GitHub Desktop.
This file contains 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 atoi(text): | |
return int(text) if text.isdigit() else text | |
def natural_keys(name): | |
text = name['name'] | |
sortKey = [ atoi(c) for c in re.split('(\d+)', text) ] | |
try: | |
return sortKey[1],sortKey[0],sortKey[3] | |
except: | |
return sortKey[1],sortKey[0] | |
races.sort(key=natural_keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment