Purify; Error : Your function fails on purify([4, 5, 5, 4]). It returns [4, 5, 4] when it should return [4, 4]


def purify(num):
    for noz in num:
        if noz % 2 == 0:
    return num

Whats wrong?


When you delete something from it, the items gets shifted from original list.

You can create a copy of original list and delete from that instead of changing original list.

to make a copy you can use slice or list() method.

x = [1,2,3]

y = list(x)
# or

y = x[:]


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