Python Practice › Tuple Programs › Program 50

Remove duplicates from a tuple

EasyTuple Programs · 50 of 70

Write a Python program to remove duplicates from a tuple, keeping the order.

Advertisement
Input
(6, 4, 9, 0, 2, 6, 1, 3, 4)
Output
(6, 4, 9, 0, 2, 1, 3)

Approach

  1. tuple(dict.fromkeys(t)).

Solution

Python
print(tuple(dict.fromkeys((6, 4, 9, 0, 2, 6, 1, 3, 4))))
Output
(6, 4, 9, 0, 2, 1, 3)
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs