Python Program to find duplicate elements in a list


In this program, you will learn how to find duplicate elements in a list in Python.


list1 = [10, 20, 10, 40, 50, 40, 10, 50, 50]

Example: How to find duplicate elements in a list in Python

list1 = [10, 20, 10, 40, 50, 40, 10, 50, 50]
v = 1

print("Duplicate elements are:")
for i in range(0, list1.__len__()):
    for j in range(i+1, list1.__len__()):
        if list1[i] == list1[j]:
            if v == 1 and list1[j] != '#':
                print(list1[i])
            list1[j] = '#'
            v = v + 1
    v = 1

Output:

Duplicate elements are:
10
40
50

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.