- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove duplicate tuples from list of tuples in Python
When it is required to remove duplicate tuples from a list of tuples, the loop, the 'any' method and the enumerate method can be used.
The 'any' method checks to see if any value in the iterable is True, i.e atleast one single value is True. If yes, it returns 'True', else returns 'False'
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
A list of tuple basically contains tuples enclosed in a list.
The enumerate method adds a counter to the given iterable, and returns it.
Below is a demonstration for the same −
Example
def delete_duplicate(my_lst): return [[a, b] for i, [a, b] in enumerate(my_lst) if not any(c == b for _, c in my_lst[:i])] my_list = [(23, 45), (25, 17), (35, 67), (25, 17)] print("The list of tuples is") print(my_list) print("The function to remove duplicates is called") print(delete_duplicate(my_list))
Output
The list of tuples is [(23, 45), (25, 17), (35, 67), (25, 17)] The function to remove duplicates is called [[23, 45], [25, 17], [35, 67]]
Explanation
- A method named 'delete_duplicate' is defined that takes a list of tuples as parameter.
- It enumerates through the list of tuples and uses the 'any' method to see if the list contains atleast a single true value.
- It returns the same as output.
- A list of tuple is defined and displayed on the console.
- The method is called by passing this list of tuple.
- This output is displayed on the console.
- Related Articles
- Remove tuples having duplicate first value from given list of tuples in Python
- Remove tuples from list of tuples if greater than n in Python
- Python | Remove empty tuples from a list
- Remove duplicate lists in tuples (Preserving Order) in Python
- Combining tuples in list of tuples in Python
- Count tuples occurrence in list of tuples in Python
- Remove tuple from list of tuples if not containing any character in Python
- Python – Remove Tuples from a List having every element as None
- Remove Tuples from the List having every element as None in Python
- Find the tuples containing the given element from a list of tuples in Python
- Remove matching tuples in Python
- Remove Tuples of Length K in Python
- Accessing nth element from Python tuples in list
- Python program to find Tuples with positive elements in List of tuples
- Convert list of tuples into list in Python

Advertisements