python 3.0以后, reduce已经不在built-in function里了, 要用它就得from functools import reduce.

reduce的用法

reduce(function, sequence[, initial]) -> value

Apply a function of two arguments cumulatively to the items of a sequence,
from left to right, so as to reduce the sequence to a single value.
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
((((1+2)+3)+4)+5).  If initial is present, it is placed before the items
of the sequence in the calculation, and serves as a default when the
sequence is empty.

意思就是对sequence连续使用function, 如果不给出initial, 则第一次调用传递sequence的两个元素, 以后把前一次调用的结果和sequence的下一个元素传递给function. 如果给出initial, 则第一次传递initial和sequence的第一个元素给function

*functool标准库还有很多功能,可以参考网上的资料

Python3 不能直接导入reduce的更多相关文章

  1. Python3中无法导入ssl模块的解决办法

    这个问题,已经困扰我好几天了,本萌新刚开始接触python,想爬取几个网页试试,发现urllib无法识别https,百度后才知道要导入ssl模块,可是发现又报错了. 本人实在无法理解为什么会报错,因为 ...

  2. 解决python3.5无法导入cv2.so的问题

    问题描述: 在python3.5环境中导入cv2报错,在python2.7中正常.注:命令行的前缀RL_2018HW是python3.5的环境. (RL_2018HW) gordon@gordon-: ...

  3. centOS安装python3 以及解决 导入ssl包出错的问题

    参考: https://www.cnblogs.com/mqxs/p/9103031.html https://www.cnblogs.com/cerutodog/p/9908574.html 确认环 ...

  4. ubuntu下安装python3.6.5导入ssl模块失败

    1.问题 python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python3 Python ( , ::) [GCC (Red Hat -)] on linux2 ...

  5. Python3之pymysql导入mysql

    $cat insert.py #!/usr/bin/python # -*- coding: UTF-8 -*- import os import sys import datetime import ...

  6. Ubuntu 18.04 Python3.6.6导入wx模块报Gtk-Message : 17:06:05.797 :Failed to load module "canberra-gtk-module"

    解决办法: root@sishen:~# apt-get install libcanberra-gtk-module

  7. python 基础 内置函数 和lambda表达式

    1.把任意数值转化为字符串有两种方法. (1)str()用于将数值转化为易于人读的形式.print(str("我是中国人"))>>>我是中国人 (2)repr() ...

  8. Python3中高阶函数lambda,filter,map,reduce,zip的详细用法

    在Python里有五大高阶函数,他们分别是lambda()匿名函数,filter()筛选函数,map()函数,reduce()函数,zip()函数.下面就让我们来详细的了解一下这五种函数的具体用法吧. ...

  9. python2.+进化至python3.+ 语法变动差异(不定期更新)

    1.输出 python2.+ 输出: print "" python3.+ 输出: print ("") 2.打开文件 python2.+ 打开文件: file ...

随机推荐

  1. oc自定义不定参数函数

    -(void)getValueFormConfig:(NSString *)key,... or -(void)getValueFormConfig:(NSString *)key,...NS_REQ ...

  2. HTML学习笔记(四)

    1.       css行内样式要注意的问题: a)     stylekeyword要作为标签的一个属性写在标签内: b)     等号后面是一对双引號包括的内容. c)      Style属性和 ...

  3. Atitit.android webview h5运行环境总结

    Atitit.android webview h5运行环境总结 1. WebView 的使用1 2. Js调用java1 3. Js调用java 跟个swt的比较2 3.1. Swt是BrowserF ...

  4. Atitit .c#的未来新特性计划草案

    Atitit .c#的未来新特性计划草案 1. C#的未来:追踪空引用1 1.1. 2. 变量命名空间1 1.2. 10. 项目引用Native dll2 1.3. 10. 项目引用Native dl ...

  5. C++语言基础(5)-this和static关键字

    一.this关键字 this是一个指针,可用其访问成员变量或成员函数 下面是使用this的一个完整示例: #include <iostream> using namespace std; ...

  6. AF_UNIX和AF_INET域的socket在epoll中的差异

    1.AF_UNIX & SOCK_STREAM 1.1 accept_socket BLOCK EPOLLIN|EPOLLET 1.2 accept_socket NON-BLOCK EPOL ...

  7. hadoop_百科

    一.发音是:[hædu:p]. 二.简介:Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储 ...

  8. finsh初步

    一. finsh在RT-Thread中被设计成一个独立的线程,它试图从外部设备中获得用户的输入,然后对用户命令进行解析执行. 正确使用finsh需要一个关联过程: rt_hw_board_init() ...

  9. mysql命令 SHOW TABLE STATUS LIKE '%city%'; 查看表的状态可以查看表的创建时间

    show status like '%handler_read_key%'; #走索引的命令的数量. #查看存储引擎 mysql> show variables like '%engine%'; ...

  10. (C#)System.Security.SecureString(表示应保密的文本)

    正常的String类型值,在脱离开作用域之后,其值在内存中并不会被立即销毁,这时如果有人恶意扫描你的内存,程序中所保存的机密信息就会暴露;于是就有了System.Security.SecureStri ...