14. remove_duplicates - I'm getting an error and I don't see what the problem is


#1



The error that I get is "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!"


The error I get is that the result I get is [5,4], but that still takes out the duplicates, so I don't see what the problem with my code is. I even made sure to test it at the bottom, and the results come out fine. In the directions, it also says that the order the results are presented in doesn't matter, so I'm completely lost on what I need to change.


def remove_duplicates(x):
    for i in x:
        if i == i:
            x.remove(i)
    return x
    
print remove_duplicates([4,5,5,4])


#2

What does your code try to do? Think it twice, bud. You should do this thing with another list. Maybe something like

new_list = []

After this I recommend looping over x just as you did, but now you should check if item is not in new list and append it there.


#3

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