关于Python 中的 map()函数

首先调用文档中关于map函数的介绍

map(function, iterable, …)

Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended withNoneitems. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

来对文档进进行说明

Apply function to every item of iterable and return a list of the results.

对可迭代函数’iterable’(迭代器)中的每一个元素应用‘function’(函数)方法,将结果作为list(列表)返回

eg:
这里写图片描述

If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel.

如果给出了额外的可迭代参数,则对每个可迭代参数中的元素‘并行(parallel)’应用‘函数‘(function) ,这里所谓的并行 大概就是同时执行的意思吧。

eg:
这里写图片描述

这就是并行的运行效果.在每个list中,取出了下标相同的元素,执行了a_b_c()

If function is None, the identity function is assumed

如果’函数 (function)’指定的是‘None’,自动假定一个‘一致(identity)’函数

if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation)

如果有多个参数,返回一个由元组组成的列表。

eg:

这里写图片描述

其实也可以这样理解这个map函数
map(f, iterable) ——> [f(x) for x in iterable] (列表推导)

若是将三个list看做矩阵的话:

1 2 3
4 5 6
7 8 9

实际上map()只做了列上面的运算

但是如果用列表推导的话 结果会成为一个提卡尔乘积。

result:

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值