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]))
def str2float(s): return float(s)
print('str2float(\'123.456\') = ', str2float('123.456'))
第三题算偷懒,没想出来用map()和reduce()怎么写
Sign in to make a reply
单身旺2016
第一题
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()怎么写