def str2float(s): dic = {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0} f = s.index('.') g = s.rindex('.') s = s[:f] + s[f + 1:] def fn1(x, y): return x * 10 + y def fn2(s): return dic[s] return reduce(fn1, map(fn2, s)) * (10 ** -g)print(str2float('123.456'))
Sign in to make a reply
张小黑900