Python program to find duplicates in an Array

In this tutorial, you will learn how to find duplicates number in an given array.

After finding duplicates we will print the how many time that element has repeated.

In this Program we will first count the occurrence of all the elements which is present in Array. 

And then we will print only those elements which has repeated more than once.

Also Read This :  Java Program to find duplicates in an Array with explanation.

Python Program to find duplicate numbers in an array.

arr, occur = [], [];
n = int(input("please enter the size of array: "))
for x in range(n):
    occur.append(0)
for x in range(n):
    element = int(input(f"please enter the element of array element between 0 to {n-1} :"))
    arr.append(element)
    occur[arr[x]]=occur[arr[x]]+1
for x in range(n):
    if occur[x]>1:
        print(f"{x} is repeated {occur[x]} times") 

Output:

python program to count duplicate in array