You are given a list L. Write a program to print all numbers in the list which are exactly repeated twice. The order of numbers should be same as in list.(for example if 3 appeared before 2 3 should be printed first.)Â
If no such number exist do not print anything. (input will be handled by us)
Input
[2,2,3,4,5,6,6,7,8,8,8,10, 3]
output
2
3
6
Explanation
Since 2, 3 and 6 is repeated 2 times output is 2, 3 and 6, whereas 8 is repeated 3 times so it is not printed.
L=[int(x) for x in input("Enter numbers: ").split(',')]
numbersRepeatedTwice=[]
for i in L:
 if L.count(i)==2 and i !="flag":
   numbersRepeatedTwice.append(i)
   L[L.index(i)]="flag"
for b in numbersRepeatedTwice:
 if numbersRepeatedTwice.index(b)==len(numbersRepeatedTwice)-1:
  print(b,end="")
 else:
  print(b)
Comments
Leave a comment