Example:
tuple = ("python", "includehelp", 43, 54.23)
Summation of tuple in list
We are given a list of tuples consisting of integer elements. We need to create a Python program to perform the summation of all elements of each tuple from the list of tuples.
Input:
[(2, 9) ,(5, 6), (1, 3, 4, 8)]
Output:
38
Method 1:
One method to solve the problem is by first creating a map of sum of elements of each tuple in Python. Then sum up all elements of the map which will be our final result.
Output:
Method 2:
To perform this task, first convert the given tuple to a list, and then flatten list element using the map() function, then perform summation of each using the sum() function, and again employ sum() for overall summation of resultant list.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer