Discuss / Python / 打卡

打卡

Topic source
# -*- coding: utf-8 -*-
from functools import reduce

def str2float(s):
    dic = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '0':0}
    def chr2list(s):
        return dic[s]
    def list2num(x, y):
        return 10 * x + y
    pos = s.index('.')
    k = len(s) - 1 - pos
    s = s[:pos] + s[pos + 1:]
    return reduce(list2num, list(map(chr2list, s)))/10**k


  • 1

Reply