]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Optimize unique_justseen() recipe for a common case. (gh-113147)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Thu, 14 Dec 2023 23:27:39 +0000 (17:27 -0600)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 23:27:39 +0000 (17:27 -0600)
Doc/library/itertools.rst

index 36cea9a835f30247cff3a56ab9ea8500e6ea9856..03127afe1b4460b28aa76759e6db8f4248b05592 100644 (file)
@@ -1017,6 +1017,8 @@ which incur interpreter overhead.
        "List unique elements, preserving order. Remember only the element just seen."
        # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
        # unique_justseen('ABBcCAD', str.lower) --> A B c A D
+       if key is None:
+           return map(operator.itemgetter(0), groupby(iterable))
        return map(next, map(operator.itemgetter(1), groupby(iterable, key)))