Remove_duplicates


#1



def remove_duplicates(sequence):
    total = []
    for x in sequence:
        if x not in total:
            total.append(x)
    return sequence

print remove_duplicates([5,5,6,6,7,7,6,4])


How do I get my code to remove all the duplicates..
the print statement returns the numbers and appends them to total, but doesn't remove the duplicates


#2

Might seem picky but make sure you're keeping track of what does what.
Return has a special meaning, print doesn't return anything, it's not even a function (although in python 3 it is)
print is also not appending anything, right.

Read your function and keep track of what's being done to what you return. (nothing at all is done, why is that? read that code, what do you return and what do you do to that?)
Don't stare at it, because it's not going to pop out at you. You gotta follow it. Keep in mind that everything is carried out exactly the way it says, nothing will get corrected no matter how obvious that something else was meant.


#3

thanks I figured out that I wasn't supposed to return sequence and I was supposed to return total


#5

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