Skip to content

Instantly share code, notes, and snippets.

@deanohyeah
Created August 2, 2013 21:00
Show Gist options
  • Save deanohyeah/6143422 to your computer and use it in GitHub Desktop.
Save deanohyeah/6143422 to your computer and use it in GitHub Desktop.
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