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'))
Sign in to make a reply
Root-F
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'))