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

posted on 2016-10-24 22:20  chinxfin  阅读(90)  评论(0编辑  收藏  举报

导航