Purify 12/15, help me


#1



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


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:
            new_numbers.append[number]
    return new_numbers


#2

new_numbers.append[number]

Following is the syntax for append() method −

list.append(obj)

#3

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


#4

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 ...

    new_numbers.append[number]

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.


#5

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