Practice makes perfect - purify


#1

So, this is my code:

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

However, both shell and codeacademy exercise throw the error: global name ‘lst2’ is not defined.
I tried adding global lst2 right at the beginning of my function but it says more or less the same. What am I doing wrong?

Thank you :slight_smile:


#2

here:

lst=[]

you want to store the even numbers in an empty list, why isn’t this list named lst2?


#3

Hi! It’s because I tried that as well and it still didn’t work! I deleted and rewrote it again and now it passed:) Thanks!


#4