diff --git a/pytools/__init__.py b/pytools/__init__.py index 44d2f1ae96bbbc003f0d17cb6a0ed747e11c4cab..778976a81d49acf7c5b0d1a0f53afd0d19f1d440 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -2317,6 +2317,13 @@ def natorder(item): def natsorted(iterable, key=None, reverse=False): """Sort using natural order [1]_, as opposed to lexicographic order. + Example:: + + >>> sorted(["_10", "_1", "_9"]) == ["_1", "_10", "_9"] + True + >>> natsorted(["_10", "_1", "_9"]) == ["_1", "_9", "_10"] + True + :arg iterable: an iterable to be sorted. It must only have strings, unless *key* is specified. :arg key: if provided, a key function that returns strings for ordering @@ -2325,13 +2332,6 @@ def natsorted(iterable, key=None, reverse=False): :returns: a sorted list - Example:: - - >>> sorted(["x10", "x1", "x9"]) == ["x1", "x10", "x9"] - True - >>> natsorted(["x10", "x1", "x9"]) == ["x1", "x9", "x10"] - True - .. [1] https://en.wikipedia.org/wiki/Natural_sort_order .. versionadded:: 2020.1