From a list of n lists, each having different numbers of element, I want to get all possible combinaison.
I make an example to help understand my problem:
If I have a list of lists like this:
a = [['a','b'], ['c','d'],['e','f','g']]
I would like to get something like this:
[[('a', 'c', 'e')],
[('a', 'c', 'f')],
[('a', 'c', 'g')],
[('a', 'd', 'e')],
[('a', 'd', 'f')],
[('a', 'd', 'g')],
[('b', 'c', 'e')],
[('b', 'c', 'f')],
[('b', 'c', 'g')],
[('b', 'd', 'e')],
[('b', 'd', 'f')],
[('b', 'd', 'g')]]
I get that with this:
list((zip(x,y,z) for x in a[0] for y in a [1] for z in a[2]))
Now I would like a function to do the same thing with any list of lists I pass too it. (No list is empty)
Something recursive like that can maybe work, but I have a hard time figure it out and something less complex and faster is maybe possible.
I found a solution in java here, but I don't know java and I can't translate it.