Discuss / Python / 第三题

第三题

Topic source
from functools import reduce
def str2float(s):
    i= len(s)-s.index('.')
    news = s.replace('.','')
    return reduce(lambda x,y:x*10+y,map(lambda s:int(s),s))/10**i

修改

from functools import reduce
def str2float(s):
    i= len(s)-s.index('.')-1
    s=s.replace('.','')
    return reduce(lambda x,y:x*10+y,map(lambda s:int(s),s))/10**i

  • 1

Reply