Python3 不能直接导入reduce
2024-08-28 13:58:57
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标准库还有很多功能,可以参考网上的资料
最新文章
- eclipse 突然 一直在loading descriptor for XXX (XXX为工程名)Cancel Requested
- OC 观察者模式(通知中心,KVO)
- [经验交流] 为 mesos framework 分配资源
- java_method_stringUtils
- 样条函数 -- spline function
- myeclipse启动tomcat会出现 a java exception has occured错误 的解决方法
- c++实现排序(简单插入,希尔,选择,快速,冒泡,堆排)
- java运行内存分配图(转)
- 问对于一个给定的n,怎样才能用最少的步骤将它变到1
- 网页设计师必备的10个CSS技巧
- 用iframe设置代理解决ajax跨域请求问题
- openerp经典收藏 深入理解报表运行机制(转载)
- 通过WebApi取出XML数据
- hdu 4775 Infinite Go(暴力)
- ds18b20再硬件设计部分的注意事项
- MONO 如何打包 .NET程序独立运行(winform篇)
- 201521123104《Java程序设计》第1周学习总结
- DRAM的原理设计
- python中split()的用法
- apollo入门demo实战(二)
热门文章
- Ant 编译项目资源不足
- 基于Linux的智能家居的设计(5)
- DNS的概念,用途,DNS查询的实现算法
- TensorFlow学习笔记 速记2 报错:failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICE
- Mysql备份工具比较
- 开源码应用之Eclipse篇
- linux服务器宕机分析/性能瓶颈分析
- virtualBox centos 6.x不能联网
- java 提取数据
- 利用JNDI的命名与服务功能来满足企业级API对命名与服务的访问