Practice Makes Perfect 14/15 Error


The error message I get is: 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!
However, I have made a copy.
This is my code:

def remove_duplicates(lst):
    newList = []
    for l in lst:
        if l in lst > 1:
    return newList

Thanks for your help!


where do you make a copy then? You remove items from lst before you made a copy, you remove items here:


Which means you are still modifying the original list


I thought that my "NewList" variable was a copy, but maybe it doesn't count as one...


no, NewList is a new list, it is not a copy of lst, even it was, it wouldn't have mattered, you still altered lst, the list passed into the function