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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -