I have n generators in a list, each arbitrary length but none of them is empty.
lst = [gen_1, gen_2, ... gen_n]
I'd like to create the list A using the generators so that each element of A
- contains zero or one element from each generator
- all generators are exhausted when finsihing the creation of A
The content of A should be something like this:
gen_1[0]
.
.
gen_1[n]
gen_1[0], gen_2[0]
.
.
gen_1[n], gen_2[0]
.
.
gen_1[n], gen_2[m], ... gen_n[o]
In essence this is like creating the powerset using itertools.combinations
(e.g. here), but we take zero to one element from each generator.
I imagine this would be solvable using recursion but can't wrap my head around it. Any help is appreciated.