Skip to content

Instantly share code, notes, and snippets.

@limed
Created July 1, 2015 17:54
Show Gist options
  • Save limed/473a498641bbc7761a20 to your computer and use it in GitHub Desktop.
Save limed/473a498641bbc7761a20 to your computer and use it in GitHub Desktop.
Sorts thing nicely in python
#!/usr/bin/python
def sort_nicely(l):
""" Sort the given list in the way that humans expect.
"""
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