Randall
Randall

Reputation: 41

Simple Lambda map function stopped working, get error "list not callable"

This very simple lambda map function used to work on Google Colaboratory but does not anymore. Gives me error " 'list' object is not callable". Anyone know why?

Result should be [2, 4, 6]

a=[1,2,3]
print(list(map(lambda x:x*2,a)))

Upvotes: 1

Views: 298

Answers (2)

user2668284
user2668284

Reputation:

list() is a built-in function.

If you code:

list = [1,2,3]

...you've now overridden the function with an actual list which is not callable

Upvotes: 1

U13-Forward
U13-Forward

Reputation: 71580

The reason is that you have a variable named list, you are overriding the original list instance.

Here is an example:

>>> type(list)
<class 'type'>
>>> list = 'foo'
>>> type(list)
<class 'str'>
>>> 

As you can see it becomes a string.

Upvotes: 1

Related Questions