snpl.util module¶
Utility functions
- snpl.util.natural_sort(li, key=<function <lambda>>)[source]¶
Sorts the list into natural alphanumeric order.
Performs an inplace natural sort on a list of strings.
- Parameters:
li (list) – List to be sorted.
key (callable) – Function that takes a single argument and returns a key to be used for sorting. Defaults to
lambda s:s
(the argument is used as the key).
- Returns:
None
Examples
>>> a = ["f2", "f0", "f10", "f1"] >>> a.sort() >>> print(a) ['f0', 'f1', 'f10', 'f2'] >>> natural_sort(a) >>> print(a) ['f0', 'f1', 'f2', 'f10']