Practice Makes Perfect 14/15 Error


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/2/4?curriculum_id=4f89dab3d788890003000096#

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:
            lst.remove(l)
    newList.append(lst[1:])
    return newList


Thanks for your help!


#2

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

lst.remove(l)

Which means you are still modifying the original list


#3

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


#4

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