Skip to content

Instantly share code, notes, and snippets.

@mazieres
Created October 3, 2014 08:55
Show Gist options
  • Save mazieres/ca72b765a5341f4e2b19 to your computer and use it in GitHub Desktop.
Save mazieres/ca72b765a5341f4e2b19 to your computer and use it in GitHub Desktop.
Ordered set python generator
def osetg(seq, idfun=None):
# Ordered set generator
# <http://www.peterbe.com/plog/uniqifiers-benchmark>
if idfun is None:
def idfun(x): return x
seen = {}
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
yield item
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment