Discuss / Python / 作业1.14/题3

作业1.14/题3

Topic source

def str2float(s):

    n = 0

    result = []

    for i in range(0, len(s)):

        if s[i] == '.':

            n = i

        else:

            result.append(s[i])

    return reduce(lambda x, y:x * 10 + y, list(map(lambda x:float(x), result))) * pow(10, -n)


  • 1

Reply