学习python3 06 map/reduce
来源:互联网 发布:剑三和尚捏脸数据 编辑:程序博客网 时间:2024/06/03 17:03
map
def f(x):... return x * x//结果r是一个Iteratorr = map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])list(r)[1, 4, 9, 16, 25, 36, 49, 64, 81] list(map(str, [1, 2, 3, 4, 5, 6, 7, 8, 9]))['1', '2', '3', '4', '5', '6', '7', '8', '9']
reduce
reduce把一个函数作用在一个序列[x1, x2, x3, …]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算,其效果就是:
reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3), x4)from functools import reducedef fn(x, y):... return x * 10 + y...reduce(fn, [1, 3, 5, 7, 9])13579from functools import reduce def fn(x, y):... return x * 10 + y... def char2num(s):... return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]... reduce(fn, map(char2num, '13579'))13579
0 0
- 学习python3 06 map/reduce
- Python学习笔记: Python3中map、filter、reduce函数
- filter、map、reduce学习
- python学习--map/reduce
- python3 中的 map,reduce,filter函数
- python3中使用map,reduce和filter
- Python3 zip,lambda,map,reduce的使用
- python3中的map,filter,reduce函数解析
- python3-map,filter,reduce,lambda函数
- python3 中的 map,reduce,filter函数
- python3中使用map,reduce和filter
- map,reduce,filter之python2,python3区别
- hadoop 学习之Map/Reduce
- Hadoop学习:Map-Reduce入门
- Python学习笔记 - map reduce
- Python学习十三:map/reduce
- 【Python学习日记】map/reduce
- python学习之map/reduce
- bootstarp模态框再嵌一个模态框,最上层的模态框中的input失效的问题
- Kubernetes(K8s)Events介绍(上)
- ArrayList的toArray
- 编译cartographer报错
- H5写的数字
- 学习python3 06 map/reduce
- Python 多进程
- Eclipse 制作API文档
- 搜索引擎之阿堂Solr学习笔记系列6(进阶篇:更新索引查询策略)
- MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建
- 安卓中,添加电池电量百分比显示的功能
- 关于AOP无法切入同类调用方法的问题
- shape和selector结合
- java中字符串转换成时间格式总结