相关疑难解决方法(0)

NameError:名称'reduce'未在Python中定义

我正在使用Python 3.2.试过这个:

xor = lambda x,y: (x+y)%2
l = reduce(xor, [1,2,3,4])
Run Code Online (Sandbox Code Playgroud)

并得到以下错误:

l = reduce(xor, [1,2,3,4])
NameError: name 'reduce' is not defined
Run Code Online (Sandbox Code Playgroud)

尝试打印reduce到交互式控制台 - 出现此错误:

NameError: name 'reduce' is not defined
Run Code Online (Sandbox Code Playgroud)


reduce在Python 3.2真的删除?如果是这样的话,还有什么选择呢?

python reduce python-3.2

176
推荐指数
3
解决办法
10万
查看次数

标签 统计

python ×1

python-3.2 ×1

reduce ×1