Python 在多个列表中生成排列

Python 在多个列表中生成排列,python,list,permutation,Python,List,Permutation,假设我有A=[A,b,c],b=[d,e],c=[f,g],我想要A,b和c之间所有可能的排列 例: 如何在python中做到这一点?一种方法是使用itertools.product: >>> from itertools import product >>> list(product(A,B,C)) [('a', 'd', 'f'), ('a', 'd', 'g'), ('a', 'e', 'f'), ('a', 'e', 'g'), ('b', '

假设我有A=[A,b,c],b=[d,e],c=[f,g],我想要A,b和c之间所有可能的排列

例:


如何在python中做到这一点?

一种方法是使用itertools.product:

>>> from 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')]

查看itertools库
>>> from 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')]