Discuss / Python / 作业3

作业3

Topic source

冰月冷望

#1 Created at ... [Delete] [Delete and Lock User]
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]
    ss=list(s)
    ind=len(ss)-ss.index('.')-1
    ss.remove('.')
    return reduce(lambda x, y: x * 10 + y, map(char2num, ss))/10**ind
print('str2float(\'0.0000123\') =', str2float('0.0000123'))

  • 1

Reply