How do you find the duplicate number on a given integer array? On Python

Q#2


Hi friends
Welcome, yesterday we solve question number 1, here solve another question
Question 2:
       How do you find the duplicate number on a given integer array?


We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time.
Let's Code and Check...


CODE:

import random
a = []
while len(a) < 100:
  ranAdd = random.randint(1,100)
  a.append(ranAdd)

print('Given Arrray: \n',a,'Total count: ',len(a))
duplicate_num = []
temp = []
for i in a:
  if i not in temp:
    temp.append(i)
  else:
    duplicate_num.append(i)

print('Given array removed from duplicate: \n',temp,'Total original count: ',len(temp))    
print('Duplicate numbers: \n',duplicate_num,'Total duplicate count: ',len(duplicate_num))

-----

By
PyKAR

Comments

Popular posts from this blog

Hardy - Ramanujan Number (Magic Number) Program in Python

FLAMES CODE ON PYTHON

Count Swap for Sorting in Python