All possible permutations of a set of lists in Python
Posted
by Ian Davis
on Stack Overflow
See other posts from Stack Overflow
or by Ian Davis
Published on 2010-05-17T22:05:15Z
Indexed on
2010/05/17
22:10 UTC
Read the original article
Hit count: 316
In Python I have a list of n lists, each with a variable number of elements. How can I create a single list containing all the possible permutations:
For example
[ [ a, b, c], [d], [e, f] ]
I want
[ [a, d, e] , [a, d, f], [b, d, e], [b, d, f], [c, d, e], [c, d, f] ]
Note I don't know n in advance. I thought itertools.product would be the right approach but it requires me to know the number of arguments in advance
© Stack Overflow or respective owner