Purify: why does it give me an error?


#1



It isnt working as expected


def purify(ysh):
    for i,j in enumerate(ysh):
        if j%2!=0:
            ysh.pop(i)
    return ysh


#2

It states in the instructions:

Do not directly modify the list you are given as input; instead, return a new list with only the even numbers.

def purify(mix):
    new = []
    for num in mix:
        if num%2 == 0:
            new.append(num)
    return new        
    
print purify([1,2,3])

I would always try to shoot for simplicty, it gets hard enough as it is :slight_smile: