I have a small snippet that does not work inexplicably.
The goal is to generate all combinations of two or more sequences.
It works when called with lists, but when called with generators, it does not.
def comb(seqs):
if seqs:
for item in seqs[0]:
for rest in comb(seqs[1:]):
yield [item] + rest
else:
yield []
if __name__=="__main__":
x=[1,2]
y=[3,4]
print list(comb([x,y]))
def gen1(): yield 1; yield 2
def gen2(): yield 3; yield 4
x=gen1()
y=gen2()
print list(comb([x,y]))
source
share