Discuss / Python / 练习第三题

练习第三题

Topic source

Wangde_ful

#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}

    def str2num(s):

        return DIGITS[s]

    s1 = s.split(".")[0]

    s2 = s.split('.')[1]

    x1 = reduce(lambda x,y:x*10+y,map(str2num,s1))

    x2 = reduce(lambda x,y:x/10+y,map(str2num,s2[::-1]))/10

    return x1+x2


  • 1

Reply