Created
April 10, 2015 14:10
-
-
Save Averroes/6e643a9ab5f33ce712fd to your computer and use it in GitHub Desktop.
removing duplicates from a sequence while maintaining order
This file contains hidden or 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
| # example.py | |
| # | |
| # Remove duplicate entries from a sequence while keeping order | |
| def dedupe(items): | |
| seen = set() | |
| for item in items: | |
| if item not in seen: | |
| yield item | |
| seen.add(item) | |
| if __name__ == '__main__': | |
| a = [1, 5, 2, 1, 9, 1, 5, 10] | |
| print(a) | |
| print(list(dedupe(a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment