- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Summation of tuples in list in Python
When it is required to sum the elements present in a list of tuple, the 'map' method and the 'sum' method can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
A list of tuple basically contains tuples enclosed in a list.
The map function applies a given function/operation to every item in an iterable (such as list, tuple). It returns a list as the result.
The 'sum' method can be used to add the elements in an iterable.
Below is a demonstration of the same −
my_list = [(11, 14), (54, 56), (98, 0), (13, 76)] print("The list is : ") print(my_list) my_result = sum(map(sum, my_list)) print("The summation of tuples in a list is: ") print(my_result)
The list is : [(11, 14), (54, 56), (98, 0), (13, 76)] The summation of tuples in a list is: 322
- A list of tuple is defined, and is displayed on the console
- The iterable is mapped to the 'sum' and all the elements are summed.
- This would again be used as parameter to 'sum' method, which gives the final result.
- This is assigned to a value.
- It is displayed on the console.
- Python - Column summation of tuples
- Combining tuples in list of tuples in Python
- Grouped summation of tuple list in Python
- Count tuples occurrence in list of tuples in Python
- Alternate element summation in list (Python)
- Summation of list as tuple attribute in Python
- Remove duplicate tuples from list of tuples in Python
- Python Grouped summation of tuple list¶
- Convert list of tuples into list in Python
- Convert list of tuples to list of list in Python
- Convert list of strings to list of tuples in Python
- Convert list of tuples to list of strings in Python
- Finding frequency in list of tuples in Python
- Custom sorting in list of tuples in Python
- Update a list of tuples using another list in Python