Skip to content

Instantly share code, notes, and snippets.

Created Jan 29, 2019
What would you like to do?
Natural sort in Python
from re import split
from glob import glob
natsort = lambda s: [int(t) if t.isdigit() else t.lower() for t in split(r'(\d+)', s)]
files = sorted(glob(path), key=natsort)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment