gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:23:20 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com