我有两个列表:T1=[[['A'], ['C']], [['B'], ['C']]]T2=[[['A'], ['B']], [['B'], ['A']]]我想将两者结合起来:我试过这个:for i in range(len(T2)): T1.insert(i,T2)结果显示如下:[[[['A'], ['B']], [['B'], ['A']]], [[['A'], ['B']], [['B'], ['A']]], [['A'], ['C']], [['B'], ['C']]]但我想要的结果应该是:[[[['A'], ['C']], [['A'], ['B']], [['B'], ['A']]], [[['B'], ['C']], [['A'], ['B']], [['B'], ['A']]]]
1 回答
皈依舞
TA贡献1851条经验 获得超3个赞
T1=[[['A'], ['C']], [['B'], ['C']]]
T2=[[['A'], ['B']], [['B'], ['A']]]
final = []
for i in T1:
ans= []
ans.append(i)
for j in T2:
ans.append(j)
final.append(ans)
print final
输出将是:
[[[['A'], ['C']], [['A'], ['B']], [['B'], ['A']]], [[['B'], ['C']], [['A'], ['B']], [['B'], ['A']]]]
想要用户想要的是这样的:
[
[
[[’A’], [’C’]], [[’A’], [’B’]], [[’B’], [’A’]]
],
[
[[’B’], [’C’]], [[’A’], [’B’]], [[’B’], [’A’]]
]
]
第一个列表中的第一个元素T1要与另一个列表的元素组合T2。
添加回答
举报
0/150
提交
取消