@萌萌的小Karl
s.split()
pow()
lambda函数
lambda x, y: x*10+y
f
def str2float(s): def char2num(s): return {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}[s] s1, s2 = s.split('.') l = lambda x, y: x*10+y return reduce(l, map(char2num, s1))+reduce(l, map(char2num, s2))/pow(10, len(s2))
Sign in to make a reply
_Ljj110719
@萌萌的小Karl
给出了python内置的的s.split()
和pow()
,这样就不用麻烦去拆分字符串blabla了,这里再用lambda函数
完成第3题(其实差不多,就是用lambda x, y: x*10+y
代替了@萌萌的小Karl
的函数f
)