我有两个元组列表,我想将它们合并为一个 例如: 清单1 = [(a,1),(b,2)] 清单2 = [(a,3),(b,4)] 我希望结果是 结果= [(a,1,3),(b,2,4)]
答案 0 :(得分:4)
>>> a = 1
>>> b = 3
>>> l1 = [(a, 1),(b,2)]
>>> l2 = [(a, 3),(b,4)]
>>> result = []
>>> for i1,i2 in zip(l1,l2):
result.append(tuple([i1[0]])+tuple(i1[1:])+tuple(i2[1:]))
>>> result
[(1, 1, 3), (3, 2, 4)]
>>>