我有一个清单
L=[['g1','g2'],['g3'],['g4','g5','g6']]
现在我想要
L*L=[['g1','g2','g3'],['g1','g2','g4','g5','g6'],['g3','g4','g5','g6']]
我如何在Python 3.5中实现它
答案 0 :(得分:6)
您可以在嵌套for循环中执行这些操作
l=[[1,2],[3],[4,5,6]]
lxl=[]
for i in range(0,len(l)):
for j in range(i+1,len(l)):
lxl.append(l[i]+l[j])
lxl看起来像这样
[[1, 2, 3], [1, 2, 4, 5, 6], [3, 4, 5, 6]]
答案 1 :(得分:3)
你想要两件事
itertools.combinations(L, 2)
获取列表中的所有子对子列总结
import itertools
LL = [a + b for a, b in itertools.combinations(L, 2)]