Python map()函数
MapReduce: Simplified Data Processing on Large Clusters Jeffrey Dean and Sanjay Ghemawat https://research.google.com/archive/mapreduce.html 这篇来自谷歌的论文介绍了map/reduce,摘录如下:
Abstract MapReduce is a programming model and an associated implementation for processing and generating large data sets. Users specify a map function that processes a key/value pair to generate a set of intermediate key/value pairs, and a reduce function that merges all intermediate values associated with the same intermediate key. Many real world tasks are expressible in this model, as shown in the paper. Programs written in this functional style are automatically parallelized and executed on a large cluster of commodity machines. The run-time system takes care of the details of partitioning the input data, scheduling the program’s execution across a set of machines, handling machine failures, and managing the required inter-machine communication. This allows programmers without any experience with parallel and distributed systems to easily utilize the resources of a large distributed system. Our implementation of MapReduce runs on a large cluster of commodity machines and is highly scalable: a typical MapReduce computation processes many terabytes of data on thousands of machines. Programmers find the system easy to use: hundreds of MapReduce programs have been implemented and upwards of one thousand MapReduce jobs are executed on Google’s clusters every day.
简而言之,map()和reduce()是在集群式设备上用来做大规模数据处理的方法,用户定义一个特定的映射,函数将使用该映射对一系列键值对进行处理,直接产生一系列键值对。
Python map()函数
Python可以接收函数作为参数。
map()是Python内置的高级函数之一,该函数可以接受其他函数作为参数,对一个序列的所有元素做该函数的映射,返回处理结果的一个map类型的对象。
同iterator,map也是一个可迭代对象。
map()用法
map(function, iterable, ...) #意即可接超过2个参数
形式:map(函数, 可迭代对象)
其语法意义就是,是用给出的函数对所有可迭代对象进行处理,返回一个map类型的对象,请注意,Java中map是键值对,相当于Python的dict,而Python中的map是一个类似与list的数据类型,不是键值对。
#!usr/bin/env python3
#_*_ coding: utf-8 _*_
def square(x):
return x * x
i = map(square, range(1,6))
print(i)
print(list(i)) #map是惰性序列,使用list计算出其所有元素的值
#结果:
<map object at 0x035E2190>
[1, 4, 9, 16, 25]
- 仿qq最新侧滑菜单
- 【高能】用PyMC3进行贝叶斯统计分析(代码+实例)
- 【Java SE】Java NIO系列教程(十二)Java NIO与IO
- 【贝叶斯系列】预测未来回报的交易算法基于Bayesian cone
- android viewgroup事件分发机制
- Rafy 领域实体框架示例(1) - 转换传统三层应用程序
- android view事件分发机制
- Rafy 领域实体框架演示(2) - 新功能展示
- ormlite介绍一
- 从Encoder到Decoder实现Seq2Seq模型(算法+代码)
- 【Java SE】Java NIO系列教程(六) Selector
- Rafy 领域实体框架演示(3) - 快速使用 C/S 架构部署
- Rafy 领域实体框架演示(4) - 使用本地文件型数据库 SQLCE 绿色部署
- spring 的OpenSessionInViewFilter简介
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Vim实用技巧——使用.swp文件恢复已删除文件
- Dart 中 final 和 const 区别
- IDEA中Lombok插件的安装与使用
- 11 | Tornado源码分析:Gen 对象(下)
- 为啥不能用uuid做MySQL的主键 ?
- 51单片机在Ubuntu下程序开发和下载
- 答应我,用了这个jupyter插件,别再重复造轮子了
- 解析 hashMap 源码之位运算
- SAP Spartacus的ComponentFactory和ComponentFactoryResolver
- 宜信OCR技术探索之版面分析业务实践|技术沙龙直播速记
- Nginx的rewrite(地址重定向)剖析
- Prometheus监控神器-Kubernetes篇(二)
- C/C++实现你的浪漫表白:浪漫流星雨表白程序
- 烂了大街的 Spring 循环依赖问题,你觉得自己会了吗
- 软件测试丨自动化测试之读取配置文件