blob: 7ad1e8cce713b156f1987b3149a8481a2b64c9aa [file] [log] [blame]
Tim Edwards7519dfb2022-02-10 11:39:09 -05001#!/usr/bin/env python3
2#
3# natural_sort.py
4# Natural sort thanks to Mark Byers in StackOverflow
5
6import re
7
8def natural_sort(l):
9 convert = lambda text: int(text) if text.isdigit() else text.lower()
10 alphanum_key= lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
11 return sorted(l, key = alphanum_key)