Created
October 3, 2014 08:55
-
-
Save mazieres/ca72b765a5341f4e2b19 to your computer and use it in GitHub Desktop.
Ordered set python generator
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
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