Skip to content

Commit 614691a

Browse files
[3.12] Optimize unique_justseen() recipe for a common case. (gh-113147) (gh-113150)
1 parent eda168f commit 614691a

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
@@ -1016,6 +1016,8 @@ which incur interpreter overhead.
10161016
"List unique elements, preserving order. Remember only the element just seen."
10171017
# unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
10181018
# unique_justseen('ABBcCAD', str.lower) --> A B c A D
1019+
if key is None:
1020+
return map(operator.itemgetter(0), groupby(iterable))
10191021
return map(next, map(operator.itemgetter(1), groupby(iterable, key)))
10201022

10211023

0 commit comments

Comments
 (0)