Python Practice › List Programs › Program 74

Remove duplicate tuples

EasyList Programs · 74 of 100

Write a Python program to remove duplicate tuples from a list.

Advertisement
Input
[(2, 3), (4, 6), (5, 1), (2, 3), (7, 9), (5, 1)]
Output
[(2, 3), (4, 6), (5, 1), (7, 9)]

Approach

  1. Tuples are hashable, so dict.fromkeys works and keeps order.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment