sort_human

snakecdysis.useful_function.sort_human(in_list, _nsre=None)[source]

Sort a list with alpha/digit on the way that humans expect,

use list.sort(key=sort_human) or

sorted(list, key=sort_human)).

Parameters:
  • in_list (list) – a python list

  • _nsre (re.compil, optional) – re expression use for compare , defaults re.compile(‘([0-9]+)’

Returns:

sorted with human sort number

Return type:

list

Example

>>> list_to_sorted = ["something1","something32","something17","something2","something29","something24"]
>>> print(sorted(list_to_sorted, key=sort_human))
['something1', 'something2', 'something17', 'something24', 'something29', 'something32']
>>> list_to_sorted.sort(key=sort_human)
>>> print(list_to_sorted)
['something1', 'something2', 'something17', 'something24', 'something29', 'something32']