Created
August 17, 2015 08:34
-
-
Save dpwiz/996e0d15c856f0c3400f to your computer and use it in GitHub Desktop.
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
# 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