s = '123.456' def str2float(s): L = s.split('.') decimal = pow(10,len(L[1])) def char2float(s): return {'0':0.0,'1':1.0,'2':2.0,'3':3.0,'4':4.0,'5':5.0,'6':6.0,'7':7.0,'8':8.0,'9':9.0}[s] return reduce(lambda x,y : x * 10 + y,map(char2float,"".join(L))) / decimal print str2float(s)
Sign in to make a reply
谭晓见
s = '123.456' def str2float(s): L = s.split('.') decimal = pow(10,len(L[1])) def char2float(s): return {'0':0.0,'1':1.0,'2':2.0,'3':3.0,'4':4.0,'5':5.0,'6':6.0,'7':7.0,'8':8.0,'9':9.0}[s] return reduce(lambda x,y : x * 10 + y,map(char2float,"".join(L))) / decimal print str2float(s)