Purify 12/15, help me



Oops, try again. 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.

why my code did not work? can somebody explain it to me please.

def purify(numbers):
    new_numbers = []
    for number in numbers:
        if number%2 ==0:
    return new_numbers



Following is the syntax for append() method −



You are close to the answer. You just have to change the type of bracket you used in the if statement.

So it should be : new_numbers.append(number)

And it should work


Hi @courseslayer39176,

This error message ...

TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

... means that you tried to apply a key or an index to an object that is not a string, sequence, or dictionary, and which therefore cannot be accessed using a key or index. In this case, that object is the append method that belongs to the list type.

The square brackets that you used here constitute syntax for access by key or index ...


As @rcodeman and @timothydavis210 have indicated, you need to pass number as an argument, rather than specify it as a key or index. Use parentheses for that.


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