听说了大名鼎鼎的 reduce 函数,可以是执行的时候却显示这个。

In [1]: reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-4c41a726eae1> in <module>()
----> 1 reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) NameError: name 'reduce' is not defined

原来自 Python3 之后,这个函数从全局命名空间中移除,放在了 functools模块,因为如果想正确执行,必须这样

In [2]: from functools import reduce

In [3]: reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])
Out[3]: 15

参考资料:

1、functools

NameError: name 'reduce' is not defined的更多相关文章

  1. NameError: name 'pip' is not defined

    NameError: name 'pip' is not defined 直接去cmd下执行...pip pip install virtualenv

  2. paip.python NameError name 'xxx' is not defined\

    paip.python NameError name 'xxx' is not defined\ 导入一个另一个文件里面的函数的时候儿,出孪这个err #这个仅仅导入孪file...要使用里面的fun ...

  3. Python3 NameError: name 'open' is not defined处理办法

    一.说明 之前默认以为python的open方法用存哪里都没什么区别的,然后昨天直接在"__del__()"中使用今天同事跑程序时反馈程序报错“Python3 NameError: ...

  4. Python class NameError name "xxx" is not defined

    Python class NameError name "xxx" is not defined 这是因为在 class 中调用了带双下划线 "__" 的函数对 ...

  5. NameError:name ‘xrange’ is not defined

    运行某代码时,报错: NameError:name 'xrange' is not defined 原因: 在Python 3中,range()与xrange()合并为range( ).我的pytho ...

  6. Firefox37.0.1+selenium 2.53+python3.6打开浏览器时报错NameError: name 'basestring' is not defined

    环境:Win7      Firefox浏览器版本37.0.1      Python36      Selenium2.53.0 在Pycharm里执行以下3行脚本: from selenium i ...

  7. Python2 错误记录1File "<string>", line 1, in <module> NameError: name 'f' is not defined

    Python 2下 count = 0 while count < 3: user = input('>>>') pwd = input('>>>') if ...

  8. NameError: name 'picamera' is not defined

    /********************************************************************************* * NameError: name ...

  9. TensorFlow:NameError: name ‘input_data’ is not defined

    在运行TensorFlow的MNIST实例时,第一步 import tensorflow.examples.tutorials.mnist.input_data mnist = input_data. ...

随机推荐

  1. 【AtCoder】ARC090

    C - Candies 前一枚举一个i,求第一行的前i个和第二行从第n个到第i个 代码 #include <bits/stdc++.h> #define fi first #define ...

  2. ORACLE 表空间扩展方法

    ORACLE 表空间扩展方法 环境: linux系统 工具:PL/SQL DEVELOPER 第一步:查看表空间的名字及文件所在位置: select tablespace_name, file_id, ...

  3. 配置免SSH

    在要远程登录别人的服务器中生成授权标识:ssh-keygen -t rsa上传至需被免登录的服务器:scp ~/.ssh/id_rsa.pub root@xx.xx.xx.xx:/root/.ssh/ ...

  4. ES7/8新特性学习随笔

    随着每年EcmaScript都会为js带来一些新特性,带来更多美化的编程体验,今天就走进一下es2016/2017所带来的新特性 ES7新特性 includes() 指数操作符 ES8新特性 asyn ...

  5. java go

    熟练掌握java技术,对多线程.数据结构有清晰的认识: 熟悉MySQL/Oracle数据库,熟悉关系数据库应用设计开发: 熟悉Spring/MyBatis/Freemarker等一种或者多种框架: j ...

  6. Wireshark数据抓包教程之安装Wireshark

    Wireshark数据抓包教程之安装Wireshark 安装Wireshark 通过上一节的学习可以根据自己的操作系统来下载安装Wireshark了.本书中已开发版1.99.7(中文版)为主,下面介绍 ...

  7. CF1067D Computer Game

    link 题意: 有 n 道题,每个题可以做很多次但只能领悟一次,一开没有领悟任何题. 对于第 i 个题,正确率为 $p_i$ .领悟之前,做对这个题可以提升 $a_i$ 的能力值:领悟之后,做对这个 ...

  8. [HDU4123]Bob’s Race

    题目大意:给定一棵$n$个点并且有边权的树,每个点的权值为该点能走的最远长度,并输入$m$个询问,每次询问最多有多少个编号连续的点,他们的最大最小点权差小于等于$Q$. 思路:两趟DP(DFS)求出每 ...

  9. haskell学习资料

    Haskell基础语法 Real World Haskell 中文版 Haskell趣学指南

  10. POP3_使用SSL链接邮箱并获取邮件

    Gmail目前已经启用了POP3和SMTP服务,与其他邮箱不同的是Gmail提供的POP3和SMTP是使用安全套接字层SSL的,因此常规的JavaMail程序是无法收发邮件的,下面是使用JavaMai ...