Answer to Question #297690 in Python for Michael

Question #297690

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.


1
Expert's answer
2022-02-14T12:04:59-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS