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 from list of tuples if greater than n
- Python | Find the tuples containing the given element from a list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Remove tuples having duplicate first value from given list of tuples
- Tuples in Python
- Python Tuples
- Python | Min and Max value in list of tuples
- Python | Remove matching tuples
- Python | Unzip a list of tuples
- Python | Column summation of tuples
- Python | Group tuples in list with same first value
- Output of Python Programs | Set 20 (Tuples)
- Python | Linear search on list or tuples
- Python | Sort Tuples in Increasing Order by any key
- Python | Position Summation in 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 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.