DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s): def fn(x,y): return x*10+y
i=s.find('.') def digit(s): return DIGITS[s] return reduce(fn, map(digit,s[0:i]))+reduce(fn,map(digit,s[i+1:]))/10**(len(s)-i-1)
print(str2float('5789.564'))
Sign in to make a reply
人人仁勇
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s): def fn(x,y): return x*10+y
print(str2float('5789.564'))