12. Practice Makes Perfect Python


#1




My code returns this:
Oops, try again. Your function fails on purify([4, 5, 5, 4]). It returns [4] when it should return [4, 4].


even though I created a new list for the even numbers in the original list x.
Whats should be changed?


def purify(x):
    for i in x:
        y = []
        if i % 2 == 0:
            y.append(i)
    
    return y


#2

Why is your list inside the loop? Trust me, that messes things up. Cut it to the line two.


#3

I did the changes you suggested and it worked! Thank you so much! I was unaware that the placement of the list would affect the code.


#4

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