当前位置:主页 > 软件编程 > Python代码 >

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

时间:2021-01-08 12:18:02 | 栏目: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

您可能感兴趣的文章:

相关文章