Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Remove Duplicates from a List


This example shows, how to remove duplicates in a given list.

Example.py
a = [10, 20, 30, 20, 10, 50, 60, 40, 80, 50, 40]

duplicate = set()
unique = []
for x in a:
    if x not in duplicate:
        unique.append(x)
        duplicate.add(x)

print(duplicate) 

Output

{40, 10, 80, 50, 20, 60, 30}

Prev Next