NameError:名称“reduce"未在 Python 中定义 [英] NameError: name 'reduce' is not defined in Python
本文介绍了NameError:名称“reduce"未在 Python 中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 Python 3.2.试过这个:
I'm using Python 3.2. Tried this:
xor = lambda x,y: (x+y)%2
l = reduce(xor, [1,2,3,4])
并得到以下错误:
l = reduce(xor, [1,2,3,4])
NameError: name 'reduce' is not defined
尝试将 reduce
打印到交互式控制台 - 出现此错误:
Tried printing reduce
into interactive console - got this error:
NameError: name 'reduce' is not defined
reduce
真的在 Python 3.2 中删除了吗?如果是这样,还有什么选择?
Is reduce
really removed in Python 3.2? If that's the case, what's the alternative?
推荐答案
已移至 functools
.
这篇关于NameError:名称“reduce"未在 Python 中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文