对python内置map和six.moves.map的区别详解

yipeiwu_com5年前Python基础

python内置map返回的是列表,而six.moves.map返回的是iter。

>>> map(lambda a: a*2, [1, 2, 3])
[2, 4, 6]
>>> m = six.moves.map(lambda a: a*2, [1, 2, 3])
>>> type(m)
<type 'itertools.imap'>
>>> next(m)
2
>>> next(m)
4
>>> m.next()
6

以上这篇对python内置map和six.moves.map的区别详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

PyQt5 QTableView设置某一列不可编辑的方法

如下所示: class EmptyDelegate(QItemDelegate): def __init__(self,parent): super(EmptyDeleg...

学习python中matplotlib绘图设置坐标轴刻度、文本

学习python中matplotlib绘图设置坐标轴刻度、文本

总结matplotlib绘图如何设置坐标轴刻度大小和刻度。 上代码: from pylab import * from matplotlib.ticker import Multi...

根据DataFrame某一列的值来选择具体的某一行方法

根据DataFrame某一列的值来选择具体的某一行方法

原始数据的DF: 此时,我要选择列名isInfected为“手足口病”的样本行: 总结:选择DataFrame里面某一列等于某个值的所有行,用一条命令即可解决即: df.loc[...

Win8.1下安装Python3.6提示0x80240017错误的解决方法

Win8.1下安装Python3.6提示0x80240017错误,如何解决? 定位原因 缺少Windows补丁KB2999226 解决方法 到Microsoft Download Cen...

Python重新引入被覆盖的自带function

幸运的是, 这一问题还是很容易解决的, 我们只需要使用__builtins__: from __builtins__ import int as py_int 这样一来我们又可以...