Purify


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/2?curriculum_id=4f89dab3d788890003000096#


Hello everyone , when i run my code i get this: "Does your purify function take exactly one argument (a list of numbers)? Your code threw a "'builtin_function_or_method' object has no attribute 'getitem'" error.

Can anyone help me?


Replace this line with your code. 

def purify(x):
    new_list = []
    for num in x:
        if num%2!=0:
            x.remove(num)
        else:
            new_list.append[num]
    return new_list


#2

Hi @adrian2,

This is unnecessary, and in fact, interferes with the iteration through x, by altering that list during the iteration ...

    x.remove(num)

#3

So , what should I replace it with?


#4

I removed it but i still get the same error


#5

Please post the most recent version of your code, so we can look at it again.


#6

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


#7

Thanks for the posted code.

The only remaining problem is the syntax of this line ...

            new_list.append[num]

The square brackets indicate to the Python interpreter that you are attempting to use num as an index or key. However, what you really need to do is to pass num as an argument, which requires parentheses instead of the square brackets.


#8

Ahh thanks! it's sooo frustrating , i swear to god , i was sitting down looking for any errors for like 30 mins and it was just a simple bracket :wink:


#9