from functools import reduce
def str2list(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':'.'}[s] def list2int(x,y): return x 10 + y def str2float(s): L = list(map(str2list,s)) LN = L.index('.') R1 = reduce(list2int,L[:LN]) R2 = reduce(list2int,L[LN+1:]) return R1+R210**-len(L[LN+1:])
Sign in to make a reply
不会潘岩
-- coding: utf-8 --
from functools import reduce
def str2list(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':'.'}[s] def list2int(x,y): return x 10 + y def str2float(s): L = list(map(str2list,s)) LN = L.index('.') R1 = reduce(list2int,L[:LN]) R2 = reduce(list2int,L[LN+1:]) return R1+R210**-len(L[LN+1:])