Remove duplicates


#1



def remove_duplicates(numbers):
    oneofeach=[]
    for number in numbers:
        if number not in oneofeacch:
            oneofeach.append(number)
    return oneofeach
    
print remove_duplicates([2,2,2,2])


I don't understand why this doesn't work. It returns "global name 'oneofeach' is not defined".
I'm completely new to coding so I have no idea what a globalname is(a web search results in an explanation which uses concepts I don't yet understand, as I have only learnt from codecademy up til this point).
can someone explain?


#2

You misspelled oneofeach as oneofeacch in the if condition. Python thinks it is a different variable, but when it looks it up, it doesn't exist, and thus it gives you an error.


#3

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