Discuss / Python / 作业

作业

Topic source

colorsumer

#1 Created at ... [Delete] [Delete and Lock User]

第三题

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import reduce

def str2float(s):
    sp=s.split('.')
    n=len(sp)>1 and len(sp[1]) or 0
    s=''.join(sp)
    return reduce(lambda a,b: a*10+b, map(lambda x:{'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[x], s))/10**n

  • 1

Reply