Skip to content

Instantly share code, notes, and snippets.

@zoranzaric
Created September 24, 2011 16:37
Show Gist options
  • Save zoranzaric/1239525 to your computer and use it in GitHub Desktop.
Save zoranzaric/1239525 to your computer and use it in GitHub Desktop.
a = ('val', 1, 1)
b = ('list', 2, [a, a])
c = ('val', 3, 2)
l = [a,b,a,c]
class MySet():
def __init__(self):
self._data = set()
def __contains__(self, value):
return (value in self._data)
def add(self, value):
self._data.add(value)
def gen(l, known):
for type, id, val in l:
if id not in known:
if type == 'list':
for inner_val in gen(val, known):
yield inner_val
yield val
known = MySet()
for x in gen(l, known):
print x
# Hier erwarte ich jetzt die Ausgabe:
# 1
# 2
# 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment