>>> def square(x):
return x ** 2
>>> map(square, [1,2,3,4,5])
<map object at 0x7f9de4ae3208>
在python2中,map()会返回一个列表,但是在python3中返回iterators
如果需要当作列表使用,必须在map()外加上list(),转换成列表。
>>> def square(x):
return x ** 2
>>> map(square, [1,2,3,4,5])
<map object at 0x7f9de4ae3208>
在python2中,map()会返回一个列表,但是在python3中返回iterators
如果需要当作列表使用,必须在map()外加上list(),转换成列表。