Discuss / Python / 第三题

第三题

Topic source

LockHart4M

#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}
    loc = None
    for i in range(len(s)):
        if s[i] == '.':
            loc = i
    def char2num(s):
        return DIGITS[s]
    part1 = reduce(lambda x, y: x * 10 + y, map(char2num, s[:loc]))
    part2 = reduce(lambda x, y: x / 10 + y, map(char2num, s[-1:loc:-1]))
    result = part1 + part2/10
    return result

  • 1

Reply