Python 扯淡的Map-Reduce
来源:互联网 发布:部落冲突国王升级数据 编辑:程序博客网 时间:2024/04/29 17:45
发现python具有类似Hadoop中的Map-reduce概念的标准函数,于是变搞来玩玩,发现还是蛮好玩的,虽然功能简陋了点,不过该做的都做了。
map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted.func是一个函数,该函数具有的参数个数根据后面iterables个数来确定,对iterables中的每个元素都作为参数调用一次func函数,并且将结果返回。也就是说调用了多少次func,就会返回多少次结果。
该map的实现是一个采用的是生成器,也就是说调用一次__next__(),才会调用一次函数返回结果。
def func(x,y): return x*y*2list=[1,2,3,4,5]result=map(func,list,list)print(result.__next__())for r in result: print(r)结果:2 8 18 32 50
其实map函数我们自己也可以实现一个版本:
def map(func,*iters): for it in zip(*iters): yield func(*it)#一定要星号*,表示需要将it元组各个元素作为多个参数,而不是将整个列表作为一个参数
注:以上记过python 3.2测试通过,python 3以上版本apply(),callable(),exefile(),file(),reduce(),reload()等方法都被移除了。
- Python 扯淡的Map-Reduce
- Python的map/reduce函数
- python 的map,reduce,filter的用法
- python map和reduce的用法
- python map和reduce的用法
- Python的map、filter、reduce函数
- Python的map、filter、reduce函数
- python map和reduce的用法
- python map和reduce的用法
- python的map,reduce,filter用法举例
- Python的map、filter、reduce函数
- Python的filter, map, reduce, lambda
- python 内置函数map、reduce的使用
- python的reduce函数和map函数
- python的map和reduce函数
- python map(),reduce()函数的使用
- python中reduce()、map()、filter()的学习
- python 学习--map 和 reduce的使用
- Java3D探奇(一)——Java 3D眼中的世界
- LINUX新手体会
- MFC 模态对话框dlg.DoModal()返回值(转)
- device_creat分析
- xapian可用的命令
- Python 扯淡的Map-Reduce
- Arm-kernel 内存收集
- 博客网站的经营——1年发展规划方案
- 引用相关
- Install and Configure ASM
- 第一次,这么狼狈的写代码。
- 学习JS基础篇
- DevExpress控件GridControl中的布局详解
- AndEngine进阶之创建高性能的文本精灵