]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Optimize unique_justseen() recipe for a common case. (gh-113147) (gh-113150)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 14 Dec 2023 23:34:00 +0000 (00:34 +0100)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 23:34:00 +0000 (23:34 +0000)
Doc/library/itertools.rst

index d79f40cd05e8f4e47b1a1a7a15b1b78ae8a8c9b4..15b449d650512acc5942d9c3b6ab837f3a0f56da 100644 (file)
@@ -1016,6 +1016,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)))