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)]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Group tuples in list with same first value
- Python | Get first element with maximum value in list of tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Count tuples occurrence in list of tuples
- Python | Combining tuples in list of tuples
- Python | Convert string tuples to list tuples
- Python | How to Concatenate tuples to nested tuples
- Python - Filter all uppercase characters Tuples from given list of tuples
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python - Extract tuples having K digit elements
- Python - Remove Tuples from the List having every element as None
- Python | Get unique tuples from list
- Python | How to get Subtraction of tuples
- Python | Get duplicate tuples from list
- Python | Min and Max value 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.