鱼C论坛

 找回密码
 立即注册
查看: 2282|回复: 8

21课!搞不清了啊!

[复制链接]
发表于 2016-12-22 17:25:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 wxb19840810 于 2016-12-22 17:26 编辑

>>> list(map(lambda x,y:[x,y],[1,3,5,7,9],[2,4,6,8,10]))

结果是:[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]

为什么不是[[1,3,5,7,9],[2,4,6,8,10]]

我的理解是,[1,3,5,7,9] 传递给 x,[2,4,6,8,10] 传递给y
                    然后执行[x,y]
                        不应该是[[1,3,5,7,9],[2,4,6,8,10]]吗?
为什么是[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]

又没有 循环在里面,怎么会 一次 一次 传递的?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-12-22 18:12:34 | 显示全部楼层
我还不会,但是你的头像和我的QQ秀一模一样
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

头像被屏蔽
发表于 2016-12-22 19:11:21 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-12-22 20:08:27 | 显示全部楼层
  1. help(map)
  2. Help on built-in function map in module __builtin__:

  3. map(...)
  4.     map(function, sequence[, sequence, ...]) -> list
  5.    
  6.     Return a list of the results of applying the function to the items of
  7.     the argument sequence(s).  If more than one sequence is given, the
  8.     function is called with an argument list consisting of the corresponding
  9.     item of each sequence, substituting None for missing values when not all
  10.     sequences have the same length.  If the function is None, return a list of
  11.     the items of the sequence (or a list of tuples if more than one sequence).
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-12-22 21:31:13 | 显示全部楼层

看不懂英文 咋办
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-22 21:50:40 | 显示全部楼层

大致意思就是说:如果给了多个列表,就按列表中每一个元素作为参数运算,如果各个列表长度不一样,长的部分就会被舍弃。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2016-12-22 21:51:37 | 显示全部楼层
看看map的定义:map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回。
虽然表面没有循环,但仍遍历每个元素
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2016-12-22 22:37:38 | 显示全部楼层
看视频
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-23 00:30:32 | 显示全部楼层
map()函數理解不到位
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-24 15:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表