Discuss / Python / str2float

str2float

Topic source

Pooki201

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

def f(dig):

        dict = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

        return dict[dig]

    def g(x, y):

        return x*10+y

    def h(a, b):

        return (a/10+b)

    return reduce(g, map(f,s[:s.find('.')])) + reduce(h, map(f, s[-1:-(len(s)-s.find('.')):-1]))/10

宋玉成

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

叹为观止。


  • 1

Reply