python 对元组列表中的每个值求和

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 对元组列表中的每个值求和相关的知识,希望对你有一定的参考价值。

from itertools import izip  // you may also just use zip
l = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 0)]

result = [sum(x) for x in izip(*l)]

print(result)

>>> [25, 20]

以上是关于python 对元组列表中的每个值求和的主要内容,如果未能解决你的问题,请参考以下文章