Skip to content

Instantly share code, notes, and snippets.

@Dih5
Last active January 12, 2017 08:51
Show Gist options
  • Save Dih5/f24750034f933efd0fe898584a49351c to your computer and use it in GitHub Desktop.
Save Dih5/f24750034f933efd0fe898584a49351c to your computer and use it in GitHub Desktop.
Key function to sort in human order
import re
def human_order_key(text):
"""Key function to sort in human order."""
# Adapted from http://nedbatchelder.com/blog/200712/human_sorting.html
return [int(c) if c.isdigit() else c for c in re.split(r'(\d+)', text)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment