Skip to content

Instantly share code, notes, and snippets.

@dpwiz
Created August 17, 2015 08:34
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 dpwiz/996e0d15c856f0c3400f to your computer and use it in GitHub Desktop.
Save dpwiz/996e0d15c856f0c3400f to your computer and use it in GitHub Desktop.
# via: http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
import re
def sort_nicely_inplace(l):
""" Sort the given list in the way that humans expect.
P.S. Beware of unicode and other i18n crap!
"""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
l.sort( key=alphanum_key )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment