Discuss / Python / 第三题代码

第三题代码

Topic source

Swordinstone

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

终于搞清楚了……

from functools import reduce
def str2float(s):
    def str2float_sub(s):
        d = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '.':'dot'}
        return d[s]
    b = list(map(str2float_sub, s))
    print (b)
    c = b.index('dot')
    print (c)
    b.pop(c)
    print (b)
    def fn(x, y):
        return x * 10 + y
    return reduce(fn, b)/10**c

print (str2float('43112.43124'))

  • 1

Reply