Nested generator functions in python
Posted
by Yuval A
on Stack Overflow
See other posts from Stack Overflow
or by Yuval A
Published on 2010-04-02T18:26:48Z
Indexed on
2010/04/02
18:33 UTC
Read the original article
Hit count: 326
Consider a tuple v = (a,b,c)
and a generator function generate(x)
which receives an item from the tuple and generates several options for each item.
What is the pythonic way of generating a set of all the possible combinations of the result of generate(x)
on each item in the tuple?
I could do this:
v = (a,b,c)
for d in generate(v[0]):
for e in generate(v[1]):
for f in generate(v[2]):
print d,e,f
but that's just ugly, plus I need a generic solution.
© Stack Overflow or respective owner