(Jul-17-2021, 11:48 PM)Skaperen Wrote: before i start coding this, does anyone know of an existing function to do this?Yes the problem is often called Human or Natural Sorting,
write a own function like DeaD_EyE is a common way,there also module like natsort
natsor works for many common cases.
>>> from natsort import natsorted >>> >>> versions = ['version-1.9', 'version-2.0', 'version-1.11', 'version-1.10'] >>> sorted(versions) ['version-1.10', 'version-1.11', 'version-1.9', 'version-2.0'] >>> natsorted(versions) ['version-1.9', 'version-1.10', 'version-1.11', 'version-2.0']Human Sorting where non-numeric characters are also ordered based on their meaning, not on their ordinal value.
Using the local decimal separator most common
en_US.UTF-8
.>>> from natsort import humansorted >>> >>> fruits = ['apple', 'apple1,4', 'Banana9,6', 'apple1,0', 'banana7,7'] >>> sorted(fruits) ['Banana9,6', 'apple', 'apple1,0', 'apple1,4', 'banana7,7'] >>> natsorted(fruits) ['Banana9,6', 'apple', 'apple1,0', 'apple1,4', 'banana7,7'] >>> >>> humansorted(fruits) ['apple', 'apple1,0', 'apple1,4', 'banana7,7', 'Banana9,6']