python中reduce函数
来源:互联网 发布:阿里数据库在哪里 编辑:程序博客网 时间:2024/05/22 05:45
Python中reduce函数,帮助文档:
>>> from functools import reduce>>> help(reduce)Help on built-in function reduce in module _functools: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.
可以看出,reduce把一个函数作用在一个序列[x1, x2, x3, …]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算,举例说明:
def add (x, y): return x+yl = [1,2,3,4,5]total = reduce (add, l)print(total)
阅读全文
0 0
- python中reduce()函数
- python中reduce()函数
- python中reduce函数
- python中map、filter、reduce 函数使用方法
- Python中reduce()函数的用法
- python中reduce函数的用法
- Python中filter、map、reduce函数
- python中的reduce函数
- Python reduce函数
- python中的reduce函数
- python中的reduce函数
- python reduce函数
- python中的reduce函数
- python中的reduce函数
- Python reduce函数
- Python-reduce函数
- python中的reduce()函数
- python的reduce()函数
- WindowInsets与fitSystemWindow相关知识总结
- 有关#define和typedef
- bzoj 5029 && poj 2528 && nyoj 1009: 贴小广告(线段树)
- OSI七层模式简单通俗理解
- html css div自适应屏幕宽度,高度
- python中reduce函数
- 解决安卓7.0拍照更换头像重启的问题(主要针对华为手机)
- 在阿里云上安装和运行Node.js全功略
- 17.Struts2__声明式异常处理
- 浅谈数据库的存储引擎
- Unity常用[xxx]用法 特性
- 深入理解虚拟DOM
- 尾部的零
- jqueryEasyUI+ztree遇到的不能加载 tabs的问题