Possible Bug in 'Purify-Practice Makes Perfect!'


This is the link to the exercise where I am stuck at.


Below is the following code. I do not receive any errors while executing this code in ipython, or ipython3.

num = [1,1,1,2,3,4,5,6,7]

def purify(num_list):
    new_list = num_list
    for i in new_list:
        if i%2:

If I define the function, and then execute the following code:



the output is given as 

[2,4,6]  which is exactly what I want.

The error I receive from codecademy is:
 "Oops, try again. Your function crashed on [1] as input because your function throws a "'NoneType' object is not iterable" error. "

But executing  purify([1]) gives me no error in python 2.7 or python 3.4

Is this an actual bug or am I forgetting something?


It is worth noting that new_list is not a copy of num_list but a reference to it. To create a discrete copy, use slicing (num_list[:]) or the .copy() method (num_list.copy()).


There is a good chance it wants you to return a value with your function.


num = [1, 2, 3, 4, 5]

def purify(num_list):
    nList = []
    for i in new_list:
        if i % 2 == 0:
    return nList

Generally when you create a function you will want to return a thing because if you don't there is no reason to write a function.


Also a function that does not return anything explicitly returns a NoneType object and that is where your error is coming from.


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