from functools import reduce def str2float(s): a=len(s)-s.find('.')-1 s=s.replace('.','') return reduce(lambda x,y:x10+y,map(int,s))/10*a print('str2float(\'123.456\')=',str2float('123.456'))
Sign in to make a reply
翁岚敏
from functools import reduce def str2float(s): a=len(s)-s.find('.')-1 s=s.replace('.','') return reduce(lambda x,y:x10+y,map(int,s))/10*a print('str2float(\'123.456\')=',str2float('123.456'))