def str2float(s):
L = list(map(char2num,s))
length = len(L)
n = 0
pos = 1
while n < length:
if L[n] == 10:
break
n = n + 1
if n < length:
pos = len(L) - n - 1
L.remove(10)
num = reduce(lambda x, y: x 10 + y, L) / (10**pos)
else:
num = reduce(lambda x, y: x 10 + y, L)
return num
print('str2float(\'123.456\') =', str2float('1234.56'))
Nicktimebreak
from functools import reduce
def char2num(s): return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.':10}[s]
def str2float(s): L = list(map(char2num,s)) length = len(L) n = 0 pos = 1 while n < length: if L[n] == 10: break n = n + 1 if n < length: pos = len(L) - n - 1 L.remove(10) num = reduce(lambda x, y: x 10 + y, L) / (10**pos) else: num = reduce(lambda x, y: x 10 + y, L) return num print('str2float(\'123.456\') =', str2float('1234.56'))