Discuss / Python / 好折腾的第三题

好折腾的第三题

Topic source

Root-F

#1 Created at ... [Delete] [Delete and Lock User]

def str2float(s): po = s.find('.') str1 = s[0:po] str2 = s[po+1:] def char2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s] def fun(str): return reduce(lambda x, y: x*10 + y, map(char2num, str)) return fun(str1) + fun(str2)/(pow(10,po)) print(str2float('123.456'))


  • 1

Reply