Discuss / Python / 三题zuoye

三题zuoye

Topic source

Lin-林堔

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

def str2float(s):

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

        return digits[s]

    for i in range(len(s)-1):

        if s[i] == '.':

            s1 = s[:i]

            s2 = s[i+1:]

            break

    rt = reduce(lambda x,y:x * 10 + y,map(str2float,s1)) + reduce(lambda x,y: x/10 + y,map(str2float,s2[::-1]))/10

    return rt


  • 1

Reply