Skip to content

Commit 5f7d735

Browse files
authored
Optimize unique_justseen() recipe for a common case. (gh-113147)
1 parent 25061f5 commit 5f7d735

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Doc/library/itertools.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,8 @@ which incur interpreter overhead.
10171017
"List unique elements, preserving order. Remember only the element just seen."
10181018
# unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
10191019
# unique_justseen('ABBcCAD', str.lower) --> A B c A D
1020+
if key is None:
1021+
return map(operator.itemgetter(0), groupby(iterable))
10201022
return map(next, map(operator.itemgetter(1), groupby(iterable, key)))
10211023

10221024

0 commit comments

Comments
 (0)