Created
November 16, 2012 17:17
-
-
Save c0ldlimit/4089123 to your computer and use it in GitHub Desktop.
Python: Unique List #(python unique list)
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
# http://www.peterbe.com/plog/uniqifiers-benchmark | |
def f5(seq, idfun=None): | |
# order preserving | |
if idfun is None: | |
def idfun(x): return x | |
seen = {} | |
result = [] | |
for item in seq: | |
marker = idfun(item) | |
# in old Python versions: | |
# if seen.has_key(marker) | |
# but in new ones: | |
if marker in seen: continue | |
seen[marker] = 1 | |
result.append(item) | |
return result | |
# OR | |
import numpy as np | |
np.unique() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment