12/15 Please check


def purify(numbers):
for key in numbers:
if key % 2 != 0:
return numbers

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

I tried to use print instead of return in the last line, it works, output [4,4]. But it crash on [1] cuz "Nonetype" output, I understand it. What is the reason return can not work?


The problem is the fact that you are modifying(removing elements from) the list while iterating it. this could mess up the iterator with some input(it will purify correctly for some inputs). you can use list comprehension to return a new list with the right values.Or you can use lambda's with the filter function. They point is try to put the results in a new list. Try to implement the method that way and if you are still stuck let us know we will definitely help.
Here is a template

def purify(numbers):
    purfied_list = []
    #...... implementation
    return purified_list


Better use ' for i in range(len(numbers)) ' for the loop if u wanna change something in it

Besides, the instruction says u need to create a new list variable for this test:

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


def purify(x):
for i in range(len(x)):
    if x[i]%2!=1:
return y