Many times, we are given a list of tuples and we need to group its keys and perform certain operation while grouping. The most common operation being addition. Let’s discuss certain ways in which this task can be performed. Apart from addition other operations can also be performed by doing small changes.
Method : Using
This task can be performed using the Counter function as it internally groups and addition operator can be used to specify the functionality on the grouped result.
The original list 1 : [('key1', 4), ('key3', 6), ('key2', 8)] The original list 2 : [('key2', 1), ('key1', 4), ('key3', 2)] The grouped summation tuple list is : [('key2', 9), ('key1', 8), ('key3', 8)]
- Python | Summation of Kth Column of Tuple List
- Python | Summation of list as tuple attribute
- Python | Accumulative index summation in tuple list
- Python - Mutiple Keys Grouped Summation
- Python - Absolute Tuple Summation
- Python | Grouped Flattening of list
- Python - Tuple to Dictionary Summation conversion
- Python - Custom Tuple Key Summation in Dictionary
- Python - Summation of tuple dictionary values
- Python - Cross tuple summation grouping
- Python - Tuple Matrix Columns Summation
- Python | Sort tuple list by Nth element of tuple
- Python - Flatten tuple of List to tuple
- Python | i^k Summation in list
- Python | Interval List Summation
- Python | Triple List Summation
- Python - Index Value Summation List
- Python | Summation of two list of tuples
- Python | Summation of tuples in list
- Python | Summation of integers in heterogenous list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.