14. remove_duplicates


#1

I keep getting this message
"Oops, try again. remove_duplicates([4, 5, 5, 4]) returned [4] instead of [4, 5]"

def remove_duplicates(Input):
    Output_list = []
    for X in Input:
        if X not in Output_list:
            Output_list.append(X)
            print X
        return Output_list

It is as if the loop only runs once. I have thought of 'for x in range()' but that is only for numbers.
I'm really stuck..


#2

a function ends the moment a return keyword is reached, if a return keyword is reached in the loop, the loop simply breaks


#3

As stetim stated, it seem you have left your return call inside your loop, so every time you run your loop, in this case, the first time you do so, the function ends. therefore giving you only the first number of the list before ending.

Hope that helps.


#4

I've just put the 'return' under the loop of 'for X in Input:' and now it works - what's weird, is that I had tried that before i wrote here and it didn't work.
Very well, it works now!
Thank you!


#5