Discuss / Python / 自认为比较简洁的

自认为比较简洁的

Topic source

第二题:

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

第三题:

def str2float(s):
    i = list(map(lambda x: DIGITS[x], s))
    return float(reduce(lambda x, y: str(x) + str(y), i))
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.'}

我是傻逼,nmd第三题搞错了


  • 1

Reply