Discuss / Python / 交作业!

交作业!

Topic source

单身旺2016

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

第一题

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

L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)

第二题

from functools import reduce

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

print('3 5 7 * 9 = ', prod([3, 5, 7, 9]))

第三题

from functools import reduce

def str2float(s): return float(s)

print('str2float(\'123.456\') = ', str2float('123.456'))

第三题算偷懒,没想出来用map()和reduce()怎么写


  • 1

Reply