利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456

def str2float(s):
def f(x, y):
return x * 10 + y

n = s.index('.')
s1 = reduce(f, map(int, s.replace('.', '')))
return s1/(10**n)
posted @ 2020-05-15 12:07  奋斗的小崽123  阅读(623)  评论(1编辑  收藏  举报