From 5f7d7353b47ccf634b9b65f933d3fdeeb395301f Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 14 Dec 2023 17:27:39 -0600 Subject: Optimize unique_justseen() recipe for a common case. (gh-113147) --- Doc/library/itertools.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 36cea9a..03127af 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -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))) -- cgit v0.12