python - 名称错误 : name 'reduce' is not defined in Py

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

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 打印到交互式控制台 - 收到此错误:

NameError: name 'reduce' is not defined


reduce 真的在 Python 3.2 中被移除了吗?如果是这样的话,还有什么办法呢?

最佳答案

已移至 functools .

关于python - 名称错误 : name 'reduce' is not defined in Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8689184/

相关文章:

python - 如何使用 Python 将整个文件目录复制到现有目录中?

python - 如何使用 brew 安装的 Python 作为默认 Python?

python - 使用 setup.py 包含非 Python 文件

python - 何时以及为什么应该使用命名元组而不是字典?

linux - 使用命令行在启动后重定向进程的 STDERR/STDOUT?

ruby - 即使在使用 rvm pkg install zlib 后也无法加载此类文件 - zli

linux - 如何将多行输出连接到一行?

python - 解释 Python 入口点?

linux - 如何在文件中搜索多行模式?

windows - Microsoft Windows 的终端多路复用器 - GNU Screen