Nested generator functions in python
- by Yuval A
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.