Skip to content

Commit

Permalink
Optimize unique_justseen() recipe for a common case. (pythongh-113147)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored Dec 14, 2023
1 parent 25061f5 commit 5f7d735
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Doc/library/itertools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)))


Expand Down

0 comments on commit 5f7d735

Please sign in to comment.