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 | Find the tuples containing the given element from a list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Combining tuples in list of tuples
- Python Tuples
- Tuples in Python
- Python | Min and Max value in list of tuples
- Python | Group tuples in list with same first value
- Output of Python Programs | Set 20 (Tuples)
- Python | Remove matching tuples
- Python | Unzip a list of tuples
- Python | Column summation of tuples
- Python | Get first element with maximum value in list of tuples
- Python | Convert dictionary to list 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.