Discuss / Python / 第三题

第三题

Topic source

zhaohanim

#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 cahr2num(s):
        return DIGITS[s]
    def trans(s):
        l = s.split(".")
        a = reduce(lambda x, y: x * 10 + y,map(cahr2num,l[0]))
        b = reduce(lambda x, y: x * 0.1 + y,map(cahr2num,l[1][::-1]))
        return a + b*0.1
    return trans(s)

  • 1

Reply