Discuss / Python / 最后一题一行版代码

最后一题一行版代码

Topic source

Yellow-Light

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

map/reduce可以写出很简洁但是不好理解的代码

# -*- coding: utf-8 -*-

from functools import reduce
import math

def str2float(s):
    return math.pow(10, -len(s.find('.'))) * reduce(lambda x, y: x * 10 + y, map(lambd z: o    rd(z) - 48, s.replace('.', '')))

  • 1

Reply