Discuss / Python / #3

蘭__吾凡

#1 Created at ... [Delete] [Delete and Lock User]
def str2float(s):
 a = s.split('.', 1)
    def change(s):
        DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
        return DIGITS[s]
    def pukai(x, y):
        return 10 * x + y
    def fenkai(b, c):
        qian = reduce(pukai, map(change, b))
        hou = reduce(pukai, map(change, c))
        return qian + hou / 10**len(c)
    return fenkai(a[0], a[1])



  • 1

Reply