MCPcopy
hub / github.com/dask/dask / natural_sort_key

Function natural_sort_key

dask/utils.py:1553–1579  ·  view source on GitHub ↗

Sorting `key` function for performing a natural sort on a collection of strings See https://en.wikipedia.org/wiki/Natural_sort_order Parameters ---------- s : str A string that is an element of the collection being sorted Returns ------- tuple[str or i

(s: str)

Source from the content-addressed store, hash-verified

1551
1552
1553def natural_sort_key(s: str) -> list[str | int]:
1554 """
1555 Sorting `key` function for performing a natural sort on a collection of
1556 strings
1557
1558 See https://en.wikipedia.org/wiki/Natural_sort_order
1559
1560 Parameters
1561 ----------
1562 s : str
1563 A string that is an element of the collection being sorted
1564
1565 Returns
1566 -------
1567 tuple[str or int]
1568 Tuple of the parts of the input string where each part is either a
1569 string or an integer
1570
1571 Examples
1572 --------
1573 >>> a = ['f0', 'f1', 'f2', 'f8', 'f9', 'f10', 'f11', 'f19', 'f20', 'f21']
1574 >>> sorted(a)
1575 ['f0', 'f1', 'f10', 'f11', 'f19', 'f2', 'f20', 'f21', 'f8', 'f9']
1576 >>> sorted(a, key=natural_sort_key)
1577 ['f0', 'f1', 'f2', 'f8', 'f9', 'f10', 'f11', 'f19', 'f20', 'f21']
1578 """
1579 return [int(part) if part.isdigit() else part for part in re.split(r"(\d+)", s)]
1580
1581
1582def parse_bytes(s: float | str) -> int:

Callers 1

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…