def str2float(s): def f(x, y): return x * 10 + y
n = s.index('.') s1 = reduce(f, map(int, s.replace('.', ''))) return s1/(10**n)