python - Generate permutation among several lists -
python - Generate permutation among several lists -
suppose have a=[a,b,c], b=[d,e], c=[f,g] , want possible permutations among a,b , c.
ex:
[[a,d,f],[a,d,g],[b,d,f],[b,d,g],[c,d,f],[c,d,g],[a,e,f],[a,e,g],[b,e,f],[b,e,g],[c,e,f],[c,e,g]]
how do in python?
one way itertools.product:
>>> itertools import product >>> list(product(a,b,c)) [('a', 'd', 'f'), ('a', 'd', 'g'), ('a', 'e', 'f'), ('a', 'e', 'g'), ('b', 'd', 'f'), ('b', 'd', 'g'), ('b', 'e', 'f'), ('b', 'e', 'g'), ('c', 'd', 'f'), ('c', 'd', 'g'), ('c', 'e', 'f'), ('c', 'e', 'g')]
python list permutation
Comments
Post a Comment