Skip to content

Commit

Permalink
Merge pull request #516 from Numerlor/everseen-key
Browse files Browse the repository at this point in the history
Do not use an identity function when no key is given in the unique_everseen recipe
  • Loading branch information
bbayles authored May 4, 2021
2 parents c076a5c + 427eccc commit e899af2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions more_itertools/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,14 @@ def unique_everseen(iterable, key=None):
``key=lambda x: frozenset(x.items())`` can be used.
"""
key = key if key is not None else lambda x: x
seenset = set()
seenset_add = seenset.add
seenlist = []
seenlist_add = seenlist.append
use_key = key is not None

for element in iterable:
k = key(element)
k = key(element) if use_key else element
try:
if k not in seenset:
seenset_add(k)
Expand Down

0 comments on commit e899af2

Please sign in to comment.