def normalize(name): return name.capitalize()
L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)
from functools import reduce def prod(L): return reduce(lambda x,y: xy, L) print('3 5 7 9 =', prod([3, 5, 7, 9]))
from functools import reduce def str2float(s): a = s.split('.') return reduce(lambda x,y: x+y/(10*(a[1].len())), map(lambda m: reduce(lambda x,y:10x+y, map(int, m)),a)) print('str2float(\'123.456\') =', str2float('123.456'))
Sign in to make a reply
________却
-- coding: utf-8 --
第一题
def normalize(name): return name.capitalize()
测试:
L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)
-- coding: utf-8 --
第二题
from functools import reduce def prod(L): return reduce(lambda x,y: xy, L) print('3 5 7 9 =', prod([3, 5, 7, 9]))
-- coding: utf-8 --
第三题
from functools import reduce def str2float(s): a = s.split('.') return reduce(lambda x,y: x+y/(10*(a[1].len())), map(lambda m: reduce(lambda x,y:10x+y, map(int, m)),a)) print('str2float(\'123.456\') =', str2float('123.456'))