您可以使用以下列表理解:[x + y for (i, x) in enumerate(a) for (j, y) in enumerate(b) if i == j]
结果:
[(1,2,3,4),(5,6,7,8)]
更新#2
您也可以使用这个列表理解来理解您的特定输入:
^{pr2}$
显然比zip版本快。在from timeit import Timer
s1 = """\
a = [(1, 2), (5, 6)]
b = [(3, 4), (7, 8)]
[x + y for (i, x) in enumerate(a) for (j, y) in enumerate(b) if i == j]
"""
s2 = """\
a = [(1, 2), (5, 6)]
b = [(3, 4), (7, 8)]
[x + y for x, y in zip(a,b)]
"""
s3 = """\
a = [(1, 2), (5, 6)]
b = [(3, 4), (7, 8)]
[a[0] + b[0], a[1] + b[1]]
"""
t1 = Timer(s1)
t2 = Timer(s2)
t3 = Timer(s3)
print ("non-zip: {0} | zip: {1} | list-concat: {2}".format(t1.timeit(), t2.timeit(), t3.timeit()))
结果(Linux x86-64上的Python 2.6.6):non-zip: 2.17631602287 | zip: 1.20438694954 | list-concat: 0.658749103546