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 | 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 | Find the tuples containing the given element from a list of tuples
- Python | Convert string tuples to list tuples
- Python | Combining tuples in list of tuples
- Python | How to Concatenate tuples to nested tuples
- Tuples in Python
- Python Tuples
- Python | How to get Subtraction of tuples
- Python | Min and Max value in list of tuples
- Python | Elementwise AND in tuples
- Python - Union of Tuples
- Python | All possible N combination 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.