Python内建函数:map/reduce
来源:互联网 发布:欠淘宝贷款3年了没还上 编辑:程序博客网 时间:2024/05/22 00:15
- map
map()
函数接收两个参数,一个是函数,一个是Iterable
, map
将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterable
返回。
举例:将列表内每个元素平方
>>> def f(x): return x*x>>> r = map(f, [1, 2, 3, 4, 5])>>> list(r)[1, 4, 9, 16, 25]
- reduce
reduce
把一个函数作用在一个序列上,这个函数必须接受两个参数,reduce
把结果继续和序列的下一个元素做累计计算 reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)
举例:对一个序列求和
>>> from functools import reduce>>> def add(x,y): return x + y>>> reduce(add, [1, 3, 5, 7, 9])25
这个例子只是为了说明reduce
的用法,求和运算可以直接用内建函数sun()
.
0 0
- python 内建函数map&reduce
- Python 内建函数,filter,map, reduce
- Python内建函数:map/reduce
- python的几个内建函数:apply(),filter(),map(),reduce()
- Python内建函数之——filter,map,reduce
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的几个内建函数:apply(),filter(),map(),reduce(
- python的几个内建函数:apply,filter,map,reduce
- python的几个内建函数:apply(),filter(),map(),reduce()
- Python内建函数之——filter,map,reduce
- Python内建函数之——filter,map,reduce
- python的lambda表达式 内建函数filter map reduce
- Python 几个内建函数: map, reduce,filter,sorted 整理
- Python内建函数之——filter,map,reduce
- Python内建函数之——filter,map,reduce
- Python内建函数之——filter,map,reduce
- python函数式编程内建函数filter,map,reduce函数
- python中的lambda匿名函数以及针对序列的内建函数map、filter和reduce
- 1022. D进制的A+B (20)
- 一名开发者修改了 composer 一行代码,性能瞬间提升,看完评论我也是醉了
- 说真的,KOOCAN觉得小三上位怎么就不能幸福了?
- 字符编码集
- Python: How to import other Python files
- Python内建函数:map/reduce
- 机器学习算法的Python实现 (3):CART决策树与剪枝处理
- AJAX JS 评论页面无刷新加载数据+TAB切换 全部 好中差JS效果。
- 使用cmake生成基于静态库的动态链接库
- 328. Odd Even Linked List
- HDU-2102-A计划(BFS)
- linux中export的作用和source命令
- Jquery中ajax方法data参数的用法
- UIL doesn't support scheme(protocol) by default You should implement this support yourself