Discuss / Python / 作业

作业

Topic source

沙耶子Ver3

#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}
def char2num(a):
    return DIGITS[a]
def fn(x, y):
    return x * 10 + y
i = 0
for x in s:
    if x == ".":
        break
    i = i + 1
return reduce(fn, map(char2num, s[:i])) + reduce(fn, map(char2num, s[i+1:])) / (10)**(len(s) - i - 1)

  • 1

Reply