代码案例
在python3
中使用python2
的模块
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> reduce
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'reduce' is not defined
>>> from six.moves import reduce
>>> def add(x, y):
... return x+y
...
>>> reduce(add,[1,2,3,4,5,6])
21
>>> reduce(lambda x ,y:x+y,[1,2,3,4,5])
15
网友评论