Remove_Duplicates using for loops, while loops and a count not working


What I don't understand is why the removal process doesn't stop before the last copy of the digit is removed. I would think my while loop would handle that by exiting before it can remove the last copy but apparently it doesn't, or it loops too many times, or something. I'm muddled up and can't figure out where the logical errors are.

I peeked at the hint and saw there was a much easier way to do this exercise, but I'd like to understand why my method fails. Thanks!

def remove_duplicates(multiples):
    for x in multiples:
    for x in multiples:
        print oncelist
        for y in oncelist:
            if x==y:
        print count
        while count >=1:
            for y in oncelist:
                if x==y:
    return oncelist


Removing from a list causes the following elements to move. If your loop doesn't account for that then you will skip elements.


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