Strange results in remove_duplicates


#1

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

I've encountered this message submitting my code:
"Oops, try again. remove_duplicates([6, 8, 122, 2, 18]) returned [4, 5, 6, 8, 122, 2, 18] instead of [8, 122, 18, 2, 6]"
while when I print remove_duplicates([6, 8, 122, 2, 18]) I get the correct result! can anyone help me with this?
I don't get what's wrong with my code.

n=[]
def remove_duplicates(l):
    for i in l:
        while i not in n:
            n.append(i)
    return n

#2

Since n is a reference object it can be seen from inside the function; however, better that it was not in global scope.

def remove_duplicates(x):
    n = []
    for i in x:
        if i not in n:     # note this line