Discuss / Python / 第三题

第三题

Topic source

B O O M!

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

def str2float(s):

    w = list(s)

    def fn(x, y):

        return x * 10 + y

    for i,value in enumerate(w):

        if value == '.':

            break

   # i =s.index('.')

    return reduce(fn,  map(int, w[0: i])) + reduce(fn,  map(int, w[i+1:])) / 10 ** len(w[i+1:])


  • 1

Reply