Skip to content

Instantly share code, notes, and snippets.

@dmeliza
Created June 13, 2013 14:30
Show Gist options
  • Save dmeliza/5774125 to your computer and use it in GitHub Desktop.
Save dmeliza/5774125 to your computer and use it in GitHub Desktop.
natural sort strings in python
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