Hi. Why i can move forward to the next lesson if i put that Code in it?

def remove_duplicates(lst):
   lst2 = []
   for i in range(0, len(lst)):
      return lst[i]

lst2 = [2,2,3,4,4,5]
print remove_duplicates(lst2)

ist not really correct, i tried just to understand how i can do this


seems you found a corner case which isn’t correctly handled by exercise validition. Please write a valid solution, after all, you are here to learn.


Thats the correct form!

def remove_duplicates(lst):
   lst2 = []
   for i in lst:
       if i not in lst2:
   return lst2

lst2 = [2,2,3,4,4,5]
print remove_duplicates(lst2)


I try the code and it is working greatly,
but I still I don’t understand
it is pretty obvious i is not in Lst2 since Lst2 is empty.
Can anyone explain plsss.


well, we are adding to lst2, so lst2 won’t stay empty for ever, so we want to ensure that what we append isn’t already in the list


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.