from functools import reduce def str2float(s): def char2num(x): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[x] n = len(s) - s.index('.') - 1 # 后面除以10的n次方 str1, str2 = s.split('.') # 获得'.'前后字符串 return reduce(lambda a, b: a * 10 + b, map(char2num, str1+str2)) / (10 ** n)
Sign in to make a reply
媳妇别开枪是我