DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s:str):
a=n=1
for i in s:
if i=='.':
a=10
else:
n=n*a
return (reduce(lambda x,y:x*10+y,map(lambda a:DIGITS[a],s.replace('.',''))))/n
Sign in to make a reply
时空软件-管理
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
def str2float(s:str):
a=n=1
for i in s:
if i=='.':
a=10
else:
n=n*a
return (reduce(lambda x,y:x*10+y,map(lambda a:DIGITS[a],s.replace('.',''))))/n