Discuss / Python / 第三题

第三题

Topic source

UTOO_NAIVE

#1 Created at ... [Delete] [Delete and Lock User]
def str2float(s):
    import math
    digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    def str2num(s1):
        return digits[s1]
    dot_idx = s.index(".")
    dec = 1 / math.pow(10, len(s) - dot_idx-1)
    new_list = s[:dot_idx] + s[dot_idx + 1:]
    return reduce(lambda x,y : x*10+y, map(str2num, new_list)) * dec

  • 1

Reply