标签: python-3.x tuples list-comprehension
我有一个包含数字的元组列表
list_numbers = [(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]
如何使用列表推导获取元组中各项总和的列表?
expected_result = [7, 9, 11, 13, 15]
答案 0 :(得分:2)
您可以遍历列表并在每个元组上调用sum()函数。
sum()
sums = [sum(t) for t in list_numbers] > [7, 9, 11, 13, 15]