我不明白这个错误是什么,怎么纠正。我想创建一个与此类似的函数:
map(lambda x: x**2, range(5))
我的地图功能:
def map(fct, *liste):
if len(liste) > 0:
for i in liste:
yield (fct(i))
如果函数调用为:
map(lambda x: x**2, [])
错误消息:
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
Tags:
删除
liste
之前的星号:或不传递空数组,而是不传递任何内容:
而且,这个条件看起来没有必要:
if len(liste) > 0:
。在这个条件下,如果列表为空,map
将返回None
,而不是空的生成器。你知道吗相关问题 更多 >
编程相关推荐