Given a list of tuples, Write a Python program to remove all the duplicated tuples from the given list.
Input : [(1, 2), (5, 7), (3, 6), (1, 2)] Output : [(1, 2), (5, 7), (3, 6)] Input : [('a', 'z'), ('a', 'x'), ('z', 'x'), ('a', 'x'), ('z', 'x')] Output : [('a', 'z'), ('a', 'x'), ('z', 'x')]
Method #1 : List comprehension
This is a naive approach to use list comprehension. Here, we use two for loops and set data structure to cancel out all the duplicates.
[(1, 2), (5, 7), (3, 6)]
Method #2 : List comprehension (Efficient approach)
This method is efficient as compared to the above method, here we use a single for loop within list comprehension and then convert it to set to remove duplicates and then again convert it to list.
[(1, 2), (5, 7), (3, 6)]
Method #3 : Python enumerate() method
[[1, 2], [5, 7], [3, 6]]
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 | Remove tuples from list of tuples if greater than n
- Python | Remove duplicate lists in tuples (Preserving Order)
- Python - Remove Duplicate subset Tuples
- Python | Get duplicate tuples from list
- Python | Find the tuples containing the given element from a list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Combining tuples in list of tuples
- Python | Convert string tuples to list 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 | Remove unordered duplicate elements from a list
- Python - Remove duplicate words from Strings in List
- Python | Convert list of tuples to list of list
- Python | How to Concatenate tuples to nested tuples
- Python | Remove empty tuples from a list
- Python | Remove all strings from a list of tuples
- Python | Remove tuple from list of tuples if not containing any character
- Python - Remove Tuples from the List having every element as None
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.
Improved By : ManasChhabra2