Discuss / Python / 只写第三题

只写第三题

Topic source
from functools import reduce
def str2float(s):
    def f(x,y):
        return x*10+y
    def g(s):
        if s!='.':
            return {'1':1,'2':2,'3':3,'4':4,'5':5,'6':6}[s]
    l=list(map(g,s))
    B=len(l[(l.index(None)+1):])
    l.pop(l.index(None))
    return reduce(f,l) / 10**B

  • 1

Reply