14/15 Your remove_duplicates modifies the list that was passed to it


here is my code :smile:

> def remove_duplicates(x):
>     q = x
>     for i in range(len(q)-1):
>         for y in range(len(q)-2):
>             if q[i] == q[y]:
>                 q.remove(q[i])
>                 y = y+1
>     return q

it return 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!

i don't know why ?? thank in advance :smiley:


please close topic..my algorithm is not good


Do you still need help? If so let me know and I will attempt to assist you.


I have the same issue kindly tell me the mistake


i figure out the issue
by typing q=x it stores the address of the list in x in q so basically q and x are same lists.
to copy x in q u need to make a list q=[] and append the values of x on q by for loop like:
for item in x:
instead of q=x
thn it will work


thank you..i realize my algorithm is not right.so i don't need your help anymore :smiley:


You could do it easier with the help of sets:
def remove_duplicates(el):
return nel

The sets module provides classes for constructing and manipulating unordered collections of unique elements.
https://docs.python.org/2/library/sets.html for more info.