Last active
January 12, 2017 08:51
-
-
Save Dih5/f24750034f933efd0fe898584a49351c to your computer and use it in GitHub Desktop.
Key function to sort in human order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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