Discuss / Python / 第三题

第三题

Topic source

啧啧ghz

#1 Created at ... [Delete] [Delete and Lock User]
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
m = len(s) 
for i in range(m):
    if s[i] == '.' :
        n = i
def char2num(s):
    return DIGITS[s]
def fn(x, y):
    return 10*x + y
return reduce(fn, map(char2num, s[:n])) + reduce(fn, map(char2num, s[n+1:]))/10**(m-n-1)

  • 1

Reply