Discuss / Python / 第三题,自己写道一半写不出来了,参考别人的写的 o,0

第三题,自己写道一半写不出来了,参考别人的写的 o,0

Topic source

张小黑900

#1 Created at ... [Delete] [Delete and Lock User]
def str2float(s):    dic = {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '0': 0}    f = s.index('.')    g = s.rindex('.')    s = s[:f] + s[f + 1:]    def fn1(x, y):        return x * 10 + y    def fn2(s):        return dic[s]    return reduce(fn1, map(fn2, s)) * (10 ** -g)print(str2float('123.456'))

  • 1

Reply