I don't know why there's an error


#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


Normal execution


Replace this line with your code. 

def remove_duplicates(numbers) :
    copy = []
    result = []
    
    for a in numbers :
        copy.append(a)
        
    copy.sort()
    result.append(copy[0])
    print result
    for i in copy :
        if i != result[len(result) - 1] :
            result.append(i)
    
    return result


#2

here:

result.append(copy[0])

if the list is empty, get the first item from list gives an index error


#3

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