前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Python map()函数

Python map()函数

作者头像
Steve Wang
发布于 2018-02-05 09:46:08
发布于 2018-02-05 09:46:08
89600
代码可运行
举报
文章被收录于专栏:从流域到海域从流域到海域
运行总次数:0
代码可运行

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()用法
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
map(function, iterable, ...)   #意即可接超过2个参数

形式:map(函数, 可迭代对象) 其语法意义就是,是用给出的函数对所有可迭代对象进行处理,返回一个map类型的对象,请注意,Java中map是键值对,相当于Python的dict,而Python中的map是一个类似与list的数据类型,不是键值对。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#!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]
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年12月18日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Python reduce()函数
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
Steve Wang
2018/02/05
7040
python里的map和reduce
http://static.googleusercontent.com/media/research.google.com/zh-CN//archive/mapreduce-osdi04.pdf
py3study
2020/01/07
9210
Notes: Hadoop-based open source projects
Here's my notes about introduction and some hints for Hadoop-based open source projects. Hope it's useful to you.
四火
2022/07/15
3210
Notes: Hadoop-based open source projects
Spark开发指南
总的来说,每一个Spark的应用,都是由一个驱动程序(driver program)构成,它运行用户的main函数,在一个集群上执行各种各样的并行操作。Spark提出的最主要抽象概念是弹性分布式数据集 (resilient distributed dataset,RDD),它是元素的集合,划分到集群的各个节点上,可以被并行操作。RDDs的创建可以从HDFS(或者任意其他支持Hadoop文件系统) 上的一个文件开始,或者通过转换驱动程序(driver program)中已存在的Scala集合而来。用户也可以让Spark保留一个RDD在内存中,使其能在并行操作中被有效的重复使用。最后,RDD能自动从节点故障中恢复。
幽鸿
2020/04/02
2K0
MapReduce 阅读笔记
这篇文章是我阅读 MapReduce 论文:《MapReduce: Simplified Data Processing on Large Clusters》的笔记,这篇笔记概述了 MapReduce 是什么,它的工作流程,一些细节问题,以及我的个人理解与思考。 《MapReduce: Simplified Data Processing on Large Clusters》: https://research.google.com/archive/mapreduce-osdi04.pdf MapReduc
CSDN技术头条
2018/02/12
9330
MapReduce 阅读笔记
Hadoop生态圈一览
根据Hadoop官网的相关介绍和实际使用中的软件集,将Hadoop生态圈的主要软件工具简单介绍下,拓展对整个Hadoop生态圈的了解。
全栈程序员站长
2022/08/31
1.2K0
Hadoop生态圈一览
Python中map()函数用法
对可迭代函数*iterables中的每个元素应用func方法,将结果作为迭代器对象返回。
王大力测试进阶之路
2020/07/23
6.1K0
python 函数式编程 map reduce
如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Processing on Large Clusters”,你就能大概明白map/reduce的概念。
葫芦
2019/04/17
3700
中英翻译谷歌论文:Percolator
Updating an index of the web as documents are crawled requires continuously transforming a large repository of existing documents as new documents arrive. This task is one example of a class of data processing tasks that transform a large repository of data via small, independent mutations. These tasks lie in a gap between the capabilities of existing infrastructure. Databases do not meet the storage or throughput requirements of these tasks: Google’s indexing system stores tens of petabytes of data and processes billions of updates per day on thousands of machines. MapReduce and other batch-processing systems cannot process small updates individually as they rely on creating large batches for efficiency.
luozhiyun
2021/10/09
1.6K0
中英翻译谷歌论文:Percolator
System|分布式|MapReduce
MapReduce被称为谷歌的三驾马车之一,主要面向谷歌的分布式计算,主要思想来自函数式编程。
朝闻君
2021/11/22
2640
System|分布式|MapReduce
MapReduce —— 历久而弥新
MapReduce 是谷歌 2004 年(Google 内部是从03年写出第一个版本)发表的论文里提出的一个概念。虽然已经过去15 年了,但现在回顾这个大数据时代始祖级别概念的背景、原理和实现,仍能获得对分布式系统的很多直觉性的启发,所谓温故而知新。
木鸟杂记
2021/09/26
3850
spark的一些小总结
首先,DAG是MR的迭代模型。其中一个优点是,DAG可以做全局的优化,而Hadoop的MR没有意识到这点。
哒呵呵
2018/08/06
3410
python builtins 内建函数
如果iterable的所有元素都是真的(或者iterable是空的),返回True。
葫芦
2019/04/17
5260
【云计算】MapReduce工作原理 - 详解图
针对MapReduce整个过程简单概括是将一个大数据计算任务通过分片成子任务,再将子任务映射到map工作处理,在通过中间过程的处理输出给reduce,reduce再将处理结果汇总。有大到小处理,再将小处理结果整合, 这也正是分治思想的本质。
司六米希
2022/11/15
8180
【云计算】MapReduce工作原理 - 详解图
Hive & Performance 学习笔记
注:本文来源于 Hortonworks 的 Adam Muise 在 July 23 2013 日的 Toronto Hadoop User Group 大会上的一次演讲, 本文只是稍作增删、整理
用户1177713
2018/02/24
1.5K0
Hive & Performance 学习笔记
大数据框架发展史
这几年大数据的飞速发展,出现了很多热门的开源社区,其中著名的有 Hadoop、Storm,以及后来的 Spark,他们都有着各自专注的应用场景。Spark 掀开了内存计算的先河,也以内存为赌注,赢得了内存计算的飞速发展。Spark 的火热或多或少的掩盖了其他分布式计算的系统身影。就像 Flink,也就在这个时候默默的发展着。
大数据老哥
2021/10/21
1.1K0
这几个Python内置的高阶函数,真香
什么是高阶函数?,一句话,就是可以接受其他函数名称作为自己参数的函数。函数式编程说的就是这个。Python中一切皆对象,函数也是一个对象,可以作为变量名称传递给其他函数调用,高阶函数就是一种特殊的函数,有 5 个内置的函数可以大大提高我们的编程效率,分别是 sorted、filter、zip、map、reduce,这里除了 zip 函数,其他都是高阶函数。它们的用武之地非常广泛,要不也不会作为内置函数了。今天分享下它们的用法,掌握之后,你一定会觉得,真香!
somenzz
2020/11/25
3940
这几个Python内置的高阶函数,真香
MIT 6.824 (2020 Spring) Lab1 - MapReduce 实现
使用的2020 Spring版的教程和Lab,最新的2021版是由Frans Kaashoek主讲,而不是Robert Morris。再加上Frans的口音都比Morris重很多,手写也比较难认,所以没有使用2021的教程。
s09g
2022/07/06
6360
MIT 6.824 (2020 Spring) Lab1 - MapReduce 实现
地图函数在 Python 中有什么用?
Python 的 map() 函数将一个函数应用于迭代器中作为输入提供的每个项目。列表、元组、集合、字典或字符串都可以用作迭代器,它们都返回可迭代的映射对象。Map() 是一个内置的 Python 函数。
很酷的站长
2023/02/20
7240
地图函数在 Python 中有什么用?
MapReduce极简教程
一个有趣的例子 你想数出一摞牌中有多少张黑桃。直观方式是一张一张检查并且数出有多少张是黑桃? MapReduce方法则是: 给在座的所有玩家中分配这摞牌 让每个玩家数自己手中的牌有几张是黑桃,然后把这
架构师小秘圈
2018/04/02
1.5K0
MapReduce极简教程
相关推荐
Python reduce()函数
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验