map will map the specified sequence according to the provided function.
For example, it is clear:
[Mapping of a function of a parameter]
#一个参数的函数的映射
def square(x):
return x**2
map(square,[1,2,3,4,5,6]
map(lambda x:x**2,[1,2,3,4,5,6])
[Mapping for functions with multiple parameters]
def mysum(x,y):
return x+y
map(mysum,[1,2,3],[11,22,33])
map(lambda x,y:x+y,[1,2,3],[11,22,33])
Corresponding exercises:
[Hash-medium] 648. Word replacement