Created
June 13, 2013 14:30
-
-
Save dmeliza/5774125 to your computer and use it in GitHub Desktop.
natural sort strings in python
This file contains hidden or 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
def natsorted(key): | |
""" key function for natural sorting. usage: sorted(seq, key=natsorted) """ | |
import re | |
return map(lambda t: int(t) if t.isdigit() else t, re.split(r"([0-9]+)",key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment