Discuss / Python / 作业

作业

Topic source

微尘初心

#1 Created at ... [Delete] [Delete and Lock User]

DIGITS = {}

for i in range(10):

    DIGITS[str(i)] = i

def char2num(s):

    return DIGITS[s]

def fn1(x, y):

     return 0.1 * x + y

def fn0(x, y):

     return x * 10 + y

def str2float(s):

    s1 = s[:s.index('.')]

    s2 = s[s.index('.') + 1:][::-1]

    L = [i for i in s2]

    L.append('0')

    return reduce(fn0, map(char2num, s1)) + reduce(fn1, map(char2num, L))


  • 1

Reply