Created
August 12, 2018 09:38
-
-
Save tenfyzhong/c2b836872b8dea0e45da416771225110 to your computer and use it in GitHub Desktop.
remove duplications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dedupe(items, key=None): | |
seen = set() | |
for item in items: | |
val = item if key is None else key(item) | |
if val not in seen: | |
yield item | |
seen.add(val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment