Python Practice › List Programs › Program 74
Remove duplicate tuples
Write a Python program to remove duplicate tuples from a list.
Input
[(2, 3), (4, 6), (5, 1), (2, 3), (7, 9), (5, 1)]
Output
[(2, 3), (4, 6), (5, 1), (7, 9)]
Approach
- Tuples are hashable, so
dict.fromkeysworks and keeps order.
Solution
data = [(2, 3), (4, 6), (5, 1), (2, 3), (7, 9), (5, 1)]print(list(dict.fromkeys(data)))Output
[(2, 3), (4, 6), (5, 1), (7, 9)]
Learn the concept
New to this topic? Read the lesson, then come back.