Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
a= [1,2,2,3]
m = map(lambda x:x**2,a)
print m
>>>[1, 4, 4, 9]
Python 3.5.0 (default, Oct 3 2015, 07:03:10)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
a= [1,2,2,3]
m = map(lambda x:x**2,a)
print(m)
>>><map object at 0x7f25b7ebce10>
list(m)
>>>[1, 4, 4, 9]
1
SErHo 2015-10-04 18:03:04 +08:00
range 和 xrange 的区别。
|
2
raptor 2015-10-04 18:28:52 +08:00
py3 的 map 返回的是迭代器。
|
3
myjiayan 2015-10-04 18:29:31 +08:00
生成器,节省内存
|
4
WhiteSaber 2015-10-04 18:37:09 +08:00
@myjiayan 感谢你的解答,生成器真是一个好东西
|