12. Practice Makes Perfect Python


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:
    return y


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


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.


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