Reputation: 41
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
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
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