Ser*_*gey 176 python reduce python-3.2
我正在使用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真的删除?如果是这样的话,还有什么选择呢?
小智 170
你可以加
from functools import reduce
Run Code Online (Sandbox Code Playgroud)
在使用reduce之前.
| 归档时间: |
|
| 查看次数: |
99828 次 |
| 最近记录: |