from functools import reduce
def str2float(s):
def text2(x,y):
return x*10+y
def text3(x,y):
return x/10+y
s1,s2=s.split('.')#根据'.'将str分成两个子串
s2=s2[::-1]#取倒序
a1=reduce(text2,map(int,s1))
a2=reduce(text3,map(int,s2))/10
return a1+a2
Sign in to make a reply
徐轲l
from functools import reduce
def str2float(s):
def text2(x,y):
return x*10+y
def text3(x,y):
return x/10+y
s1,s2=s.split('.')#根据'.'将str分成两个子串
s2=s2[::-1]#取倒序
a1=reduce(text2,map(int,s1))
a2=reduce(text3,map(int,s2))/10
return a1+a2