My remove_duplicates modifies the list


#1

i have this error :::>Oops, try again. Your remove_duplicates modifies the list that was passed to it. [4, 5, 5, 4] was modified to [5, 4]. Perhaps you should make a copy first!

what is the problem ?,

def remove_duplicates(x):
for i in x :
if i == i:
x.remove(i)
return x


14. Remove_duplicates
#2

Hi @hydra_95,

The instructions include this ...

Do not modify the list you take as input! Instead, return a new list.

The list you take as input is x, and you are modifying it with the remove method.

Instead ...

  • Create a new empty list prior to the loop.
  • Within the loop, check each item in x, and if it is not in the new list, append it to that new list.
  • After the loop, return the new list.

If any problem occurs as you refine your code, you can post it again. It would be best to format all code that you post, so we can see details such as indentation.


#3

thank you for helping .....i have :grin: found the solution


#4