Created
June 28, 2013 15:23
-
-
Save cogumbreiro/5885507 to your computer and use it in GitHub Desktop.
Generator of an ordered set from a sequence of elements.
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 ordered_set(elems): | |
""" | |
Returns a generator for an order set created from the given elements. | |
""" | |
data = set() | |
for elem in elems: | |
before = len(data) | |
data.add(elem) | |
after = len(data) | |
if before != after: | |
yield elem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment