Python thinks 5 divided by 2 remainders 0


#1

How do I get it to think that 5%2=1?

def purify(a):
    x = a
    print x
    for i in x:
        if i % 2 == 0:
            print i % 2
        else:
            print i
            x.remove(i)
    return x
print purify([4, 5, 5, 4])

print 5 % 2"


#2

I am confused by the question, the problem you have here, lets go through our array. the first item (index 0) is 4, 4 % 2 is zero, so the if statement is true, the second item (index 1) is 5, 5 % 2 is not zero, so else gets executed, and 5 gets removed. Now we have a problem, because now we are going to next item (index 2), but item at index 2 (purify[2]) is now 4. Because you removed an item, the index shifts, and it skips the second 5 (now at index 1). So, you either need to figure out a way to resolve this issue, or you need another, for example appending even numbers to a new list