Discuss / Python / 挑战最简洁的三道题

挑战最简洁的三道题

Topic source

第一题

def normalize(name):    return name.title()

第二题

def prod(L):    return reduce(lambda x, y: x * y, L)

第三题

def str2float(s):    dot = len(s) - s.index('.')    s = s.replace('.', '')    return reduce(lambda x, y: x * 10 + y, map(lambda x: int(x), s)) / (10 ** (dot - 1))

  • 1

Reply