14. remove_duplicates. my code nor work


#1



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

Oops, try again.
remove_duplicates([]) resulted in an error: list index out of range


My english is bad. Sorry.
Tell me, please, why does my code not work in Codecademy?
I see, this is not a simple code.


def remove_duplicates(y):
    x=[]
    for i in range(len(y)):
        x.append(y[i])
    x=sorted(x)
    i=0
    while i<=len(x):
        if i==len(x)-1:
            break
        elif x[i]==x[i+1]:
            del x[i+1]
            i-=1
        i+=1
    return x


#2

you where so close, this line:

while i<=len(x):

arrays are zero indexed based, so you want numbers lesser then the length:

while i<len(x):

#4

Nice!
Only one character to our second victory.