Given a tuple containing a bunch of integer elements, how can one find the sum of all the elements?
For example, if I have a list of tuples:
li = [(1
Both solutions below will work.
li = [(1, 2), (1, 3), (2, 3)] print([sum(i) for i in li])
or
def sumtupleinlist(lst): return [sum(i) for i in lst] li = [(1, 2), (1, 3), (2, 3)]
To test the function, run :
print(sumtupleinlist(li))