DS301222 #5th Funny Puzzles of the Day

Write a Python function that takes a list of integers as input and returns a list of all the integers that appear more than once in the input list.

@vaishu.swap10112016

Correct, keep it up.

@vaishu.swap10112016 ,
The question said you have to return a list of all integers that appear more than once in input i.e. duplicate elements.
So, from my understanding your code should have returned [3] instead it returns [1,2,3,4,5]
correct me if I am wrong please

1 Like

@kharshavardhan31you are correct.

sorry, but i didn’t get you

now is this ok??

@vaishu.swap10112016 yeah This is right. you only needed to return elements with count more than one.
For your first code also, you were only missing logic for storing duplicates.

def duplicates_list(l):
      x = []
      duplicates = []
      for i in l:
           if i not in x:
                  x.append(i)
           else:
                  duplicates.append(i) 
     return duplicates                 

your code was returning unique numbers instead of duplicate numbers.