Skip to content

Instantly share code, notes, and snippets.

@zahna
Created October 2, 2017 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zahna/ee9c7d85400800b4873289213086813f to your computer and use it in GitHub Desktop.
Save zahna/ee9c7d85400800b4873289213086813f to your computer and use it in GitHub Desktop.
optimized natural sorting key function
def alphanum_key(s):
'''http://nedbatchelder.com/blog/200712/human_sorting.html'''
tryint = lambda s: int(s) if s.isdigit() else s
return [ tryint(c) for c in re.split('(\d+)', s) ]
alist.sort(key=alphanum_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment