Created
September 30, 2011 16:53
-
-
Save adamchandra/1254338 to your computer and use it in GitHub Desktop.
unique
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
| # order preserving uniq-ify | |
| def unique(seq, ident=None): | |
| if ident is None: ident = lambda x: x | |
| seen, result = set(), [] | |
| for item in seq: | |
| marker = ident(item) | |
| if marker not in seen: | |
| seen.add(marker) | |
| result.append(item) | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
order preserving uniq unique python