Question in "remove_duplicates"


In "remove_duplicates"exercise, my code is as followed. there is not syntax error but the result is wrong. what's wrong with my code?

def remove_duplicates(numbers):
    for i in range(len(numbers)):
        for j in range(i+1,len(numbers)):
            if numbers[i]==numbers[j]:
    return new_numbers


You need to account for that removing elements causes values to move in the list.
Also note that assignment does not create a copy, so new_numbers and numbers are referring to the same list.


thank you for reminding the use of .pop() which i really didn't notice.
however, i think that this is not the main problem of my code since my code couldn't function even after fixing the problem you had mentioned


If it's still not working then how can you tell you fixed it? I'm very confused, and my guess is that you just didn't fix it.

Observe what your code does and compare to what you want it to do. Find the difference.


Hi all,

I solved this practice as the following code;


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