赞
踩
map(function,iterable)
function:函数
iterable:一个或者多个序列
>>> def square(x):
>>> return x ** 2
>>> map(square,[1,2,3,4,5])
<map at 0xbd26f28>
>>> list(map(square,[1,2,3,4,5]))
[1, 4, 9, 16, 25]
>>> def add(x,y,z):
>>> return x + y + z
>>> list1 = [1,2,3]
>>> list2 = [1,2,3,4]
>>> list3 = [1,2,3,4,5]
>>> res = map(add,list1,list2,list3) #有截断功能,按最短的算
>>> print(list(res)) #1+1+1,2+2+2,3+3+3
[3, 6, 9]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。