How do I sum the first value in each tuple in a list of tuples in Python?

后端 未结 8 725
时光取名叫无心
时光取名叫无心 2020-12-05 10:03

I have a list of tuples (always pairs) like this:

[(0, 1), (2, 3), (5, 7), (2, 1)]

I\'d like to find the sum of the first items in each pai

8条回答
  •  [愿得一人]
    2020-12-05 10:34

    If you don't mind converting it to a numpy array, you can use np.sum over axis=0 as given here

提交回复
热议问题