# -*- coding: utf-8 -*-
from functools import reduce
def str2float(s):
n = 0
for ch in s :
if ch == '.' :
index = n
break
n = n + 1
s = s[0:n] + s[n + 1 : len(s)]
def char2num(L) :
return{'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[L]
def fn(x,y) :
return x * 10 + y
return reduce(fn,map(char2num,s))/ pow(10,len(s) - n -1)
print('str2float(\'123.456\') =', str2float('123.456'))
泪语花
受拼接字符串的启发= =