且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中的元组列表中对每个元组的第一个值求和?

更新时间:2022-12-08 23:17:09

与Python 2.3兼容的版本是

A version compatible with Python 2.3 is

sum([pair[0] for pair in list_of_pairs])

或在最新版本的Python中,请参见此答案

or in recent versions of Python, see this answer or this one.