简体   繁体   中英

Python - Merge two lists of tuples into one

我有两个元组列表,我想将它们合并为一个 Ex:List1 = [(a, 1),(b,2)] List2 =[(a, 3),(b,4)] 我希望结果为结果 = [(a, 1,3),(b,2,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)]
>>> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM