from functools import reduce
from cv2 import split
num_dict = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def char2num(s):
return num_dict[s]
def str2float(s):
s1,s2=s.split('.')
xz=reduce(lambda x,y:10*x+y,map(char2num,s1))
xf=(reduce(lambda x,y:10*x+y,map(char2num,s2))/(10**len(s2)))
x=xz+xf
return x
str2float('123.456')
Sign in to make a reply
岁羽谌谌
from functools import reduce
from cv2 import split
num_dict = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def char2num(s):
return num_dict[s]
def str2float(s):
s1,s2=s.split('.')
xz=reduce(lambda x,y:10*x+y,map(char2num,s1))
xf=(reduce(lambda x,y:10*x+y,map(char2num,s2))/(10**len(s2)))
x=xz+xf
return x
str2float('123.456')