1 def str2int(s): 2 def fn(x,y): 3 return x+y 4 def char2num(s): 5 return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s] 6 return reduce(fn,map(char2num,s)) 7 8 print(str2int('2468')) 9
1 def str2int(s): 2 def fn(x,y): 3 return x+y 4 def char2num(s): 5 return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s] 6 return reduce(fn,map(char2num,s)) 7 8 print(str2int('2468')) 9
转载于:https://www.cnblogs.com/lixiaolun/p/4755896.html