首页 > 代码库 > map&reduce

map&reduce

#map list输出

>>> map(str,[1,2,3,4])

[‘1‘, ‘2‘, ‘3‘, ‘4‘]

 

#函数fn
def fn(x,y):
return x*10+y

#函数char2num
>>> def char2num(s):
return{‘0‘:88,‘1‘:77,‘2‘:66}[s]

#reduce fn函数map char2num
>>> reduce(fn,map(char2num,‘012‘))
9636

 

#过程:1.88,77,66 2.88*10+77=957 3.957*10+66=9636

map&reduce