Reputation: 1094
I know there must be a quick way to do this, but can't seem to find it. I need to find a way to add the items in a tuple. i was hoping for something like mytuple.sum.
I have a list of tuples like mylist= [(1,3,5,3),(1,5,5,5),....,(1,3,2,1),(1,1,1,2)]
and need to be able to call on it similarly to mylist[0].sum
Thanks!
Upvotes: 0
Views: 1287
Reputation: 1475
It's hard to tell what you want, but it's probably one of
sum(mylist[0])
or
sum(sum(x) for x in mylist)
or
map(sum, mylist)
Upvotes: 1