Sort alphanumeric strings naturally, i.e. with "1" before "10". Based on http://stackoverflow.com/a/4836734.
(iterable, reverse=False)
| 34 | |
| 35 | |
| 36 | def 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 | |
| 49 | def oscillate(iterable, max_passes=np.inf): |
no test coverage detected