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 list as tuple attribute
- Python | Grouped Flattening of list
- Python | Alternate element summation in list
- Python | Position Summation in List of Tuples
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Pair and combine nested list to tuple list
- Python | Merge list of tuple into list by joining the strings
- Python | Convert a list into a tuple
- Python | Dictionary to list of tuple conversion
- Python | Join tuple elements in a list
- Python | Reverse each tuple in a list of tuples
- Python | Modifying tuple contents with list
- Python | Convert a list into tuple of lists
- Python | Ways to iterate tuple list of lists
- Python | Count the elements in a list until an element is a Tuple
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.