【发布时间】:2021-11-24 05:45:54
【问题描述】:
以下代码显示我尝试映射函数列表并得到“'list'对象不可调用”的类型错误。
L1的类型是'map',所以我用list函数转换了,还是报错。
您对这个问题有任何想法吗?谢谢!
import math
func_list=[math.sin, math.cos, math.exp]
result=lambda L: map(func_list, L)
L=[0,0,0]
L1=result(L)
for x in L1:
print(x)
结果类型为<class 'function'> 结果类型为<class 'map'>
Traceback (most recent call last)
<ipython-input-22-17579bed9240> in <module>
6 print("the type of result is " + str(type(result)))
7 print("the type of result is " + str(type(L1)))
----> 8 for x in L1:
9 print(x)
TypeError: 'list' object is not callable
【问题讨论】:
-
map需要一个函数作为它的第一个参数,但[math.sin, math.cos, math.exp]不是一个函数,它是一个列表。你期待它做什么? -
这道题是用函数列表和lambda函数计算math(sin(0))、math(sin(0))、math(sin(0))。感谢您澄清这个问题。