Given a list of tuple, the task is to sum the tuples having same first value.
Input: [(1, 13), (2, 190), (3, 82), (1, 12)] Output: [(1, 25), (2, 190), (3, 82)] Input: [(1, 13), (1, 190), (3, 25), (1, 12)] Output: [(1, 215), (3, 25)]
Let’s discuss the different ways we can do this task.
Method #1: Using
[(1, 215), (3, 25)]
Method #2: Using
[(1, 95), (2, 204), (3, 82)]
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Combining tuples in list of tuples
- Python Tuples
- Tuples in Python
- Python | Min and Max value in list of tuples
- Python | Unpacking nested tuples
- Python | Initialize tuples with parameters
- Python | Get unique tuples from list
- Python | Remove matching tuples
- Python | Group tuples in list with same first value
- Python | Column summation of tuples
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.