Articles

Program to find duplicate element from a list in Python

Program to find duplicate element from a list in Python


In this python article, we are going to learn

  • program to find the duplicate element in a list in python

Program to find duplicate element from a list in Python

The program is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

marks = [22,66,43,58,98,42,77,56,66]

unique_marks = list()

for i in marks:
    if i not in unique_marks:
        unique_marks.append(i)
    else:
        print("The duplicated element is:",i)
        break

The output of the program is:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
The duplicated element is: 66

Few important tips about the program

1. In the given program, we iterate upon the given list and see if it is already present in the newly created list. If the element is not present, we insert that element into the list.

2. Else we consider it to be the duplicated element.

 

find-duplicate-element-from-a-list-in-python

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Oct 13,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!