# -*- coding: utf-8 -*-
from functools import reduce
L = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.'}
def xx(p):
return L[p]
def fn(x, y):
return x * 10 + y
def str2float(s):
n = len(s.split('.')[1])
m = s.split('.')[0] + s.split('.')[1]
return reduce(fn, map(xx, m)) * 10**-n
Sign in to make a reply
陈妍素姬
# -*- coding: utf-8 -*-
from functools import reduce
L = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.'}
def xx(p):
return L[p]
def fn(x, y):
return x * 10 + y
def str2float(s):
n = len(s.split('.')[1])
m = s.split('.')[0] + s.split('.')[1]
return reduce(fn, map(xx, m)) * 10**-n