Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
Created November 16, 2012 17:17
Show Gist options
  • Save c0ldlimit/4089123 to your computer and use it in GitHub Desktop.
Save c0ldlimit/4089123 to your computer and use it in GitHub Desktop.
Python: Unique List #(python unique list)
# 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