二 使用
用法
map(func, seq1[, seq2,…])
map接收两个参数,第一个参数是函数名,第二个是一个或多个可迭代的序列,返回的是一个集合。...比如需要将seq的元素乘以2 ,使用map可以写成
In [4]: l=[1, 2, 3, 4, 5, 6, 7, 8, 9]
In [5]: map(lambda x:x*2 ,l)
Out[5...In [1]: print map(lambda x , y : x ** y, [2,4,6],[3,2,1])
[8, 16, 6]
seq1=[2,4,6] ,seq2=[3,2] 元素个数不一致则报错...** y, [2,4,6],[3,2])
---------------------------------------------------------------------------
TypeError...: unsupported operand type(s) for ** or pow(): 'int' and 'NoneType'
In [4]:
2.3 map在多进程中的应用。