Purify...Why doesn't this work? It is supposed to work right


#1

def purify(listofnum):
    for index,element in enumerate(listofnum):
        if element%2 !=0:
            #listofnum.pop(index)
            del(listofnum[index])
            #listofnum.remove(element) 
        print listofnum
    return listofnum


print purify([4,5,5,4])

Note: The indents don't show up in this...But, the indentation is all correct


#2

looping over the list you are removing from causes index shift, this will cause problems

I recommend the opposite approach, append even numbers to a new list


#3

Oh...correct...thanks a lot
I forgot that the index changes if I remove an element


#4