python把str转换为int

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     

 

posted @ 2015-08-24 21:04  Entropy_lxl  阅读(4916)  评论(0编辑  收藏  举报