Discuss / Python / 学习

学习

Topic source

最帅的仔

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

第一题:

def capitalize(L):
    return list(map(lambda a: a[0].upper() + a[1:].lower(), L))
# 或者
def normalize(L):
    return list(map(lambda a: a.title(), L))

第二题:

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

第三题:

def str2float(str):
    s = str.replace('.', '')
    num = 10 ** (len(str) - str.find('.') - 1)
    return reduce(lambda a, b: a * 10 + b, map(lambda v:int(v),s)) / num

  • 1

Reply