Skip to content

Instantly share code, notes, and snippets.

@adamchandra
Created September 30, 2011 16:53
Show Gist options
  • Save adamchandra/1254338 to your computer and use it in GitHub Desktop.
Save adamchandra/1254338 to your computer and use it in GitHub Desktop.
unique
# 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
@adamchandra
Copy link
Author

order preserving uniq unique python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment