MCPcopy Create free account
hub / github.com/DedalusProject/dedalus / natural_sort

Function natural_sort

dedalus/tools/general.py:36–46  ·  view source on GitHub ↗

Sort alphanumeric strings naturally, i.e. with "1" before "10". Based on http://stackoverflow.com/a/4836734.

(iterable, reverse=False)

Source from the content-addressed store, hash-verified

34
35
36def natural_sort(iterable, reverse=False):
37 """
38 Sort alphanumeric strings naturally, i.e. with "1" before "10".
39 Based on http://stackoverflow.com/a/4836734.
40
41 """
42
43 convert = lambda sub: int(sub) if sub.isdigit() else sub.lower()
44 key = lambda item: [convert(sub) for sub in re.split('([0-9]+)', str(item))]
45
46 return sorted(iterable, key=key, reverse=reverse)
47
48
49def oscillate(iterable, max_passes=np.inf):

Callers 5

visit_writesFunction · 0.85
get_assigned_writesFunction · 0.85
get_all_writesFunction · 0.85
get_assigned_setsFunction · 0.85
merge_distributed_setFunction · 0.85

Calls 2

convertFunction · 0.85
splitMethod · 0.45

Tested by

no test coverage detected