Discuss / Python / 第三题

第三题

Topic source

王珺飞MCFC

#1 Created at ... [Delete] [Delete and Lock User]
    def fn1(x, y):
        return x * 10 + y    
    def fn2(x, y):
        return x * 0.1 + y
    def char2num(s):
        return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]
    a, b = s.split('.')
    return reduce(fn1, map(char2num, a)) + reduce(fn2, map(char2num, b[::-1])) / 10

  • 1

Reply