1.

Write a program to find all duplicates in a list.

Answer»

a =[1,2,3,2,1,5,6,5,5,5] 

d={ } 

for elem in a: 

if elem in 

d: d[elem] + = 1 

else: 

d[elem] = 1 

print elem 

print [x for x, y in d.items() if y > 1], 

print “have duplicates” 

print d 

Output screenshot:

[1,2,5] have duplicates 

{1:2,2: 2,3:1,5:4, 6: 1}



Discussion

No Comment Found