from functools import reduce 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 create_char(s): a = s.index('.') return s[:a], s[a + 1:] x, y = create_char(s)
def char2num(s): return DIGITS[s] def fn1(j, k): return j*10+k a = reduce(fn1, map(char2num, x)) b = reduce(fn1, map(char2num, y)) def divide(lengh, c): while lengh>0: c=c/10 lengh = lengh-1 return c c = divide(len(str(b)), b) return a+c
Sign in to make a reply
嬉皮小丸子
from functools import reduce 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 create_char(s): a = s.index('.') return s[:a], s[a + 1:] x, y = create_char(s)