有没有知道怎么解释这段代码的 有点摸不着头脑
from functools import reduce 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] if '.' in s: L=s.split('.') left_part=reduce(lambda x,y:x*10+y,map(char2num,L[0])) # 123.456 right_part=reduce(lambda x,y:x/10+y,map(char2num,L[1][::-1]))/10 return left_part + right_part else: return reduce(lambda x,y:x*10+y,map(char2num,s)) print('str2float(\'123.456\') =', str2float('123.456'))
有没有大神可以给点注释,很多地方都看不太明白