假设我有以下内容。
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [['a','b'],['c','d'],['e','f']]
我如何获得以下内容?
[1,2,3,'a','b']
[1,2,3,'c','d']
[1,2,3,'e','f']
[4,5,6,'a','b']
[4,5,6,'c','d']
[4,5,6,'e','f']
[7,8,9,'a','b']
[7,8,9,'c','d']
[7,8,9,'e','f']
最佳答案
from itertools import product
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [['a','b'],['c','d'],['e','f']]
print [x+y for (x,y) in product(a,b)]
关于python - 获得列表的所有组合(笛卡尔积)的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11299236/