题目1:利用map()
函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。输入:['adam', 'LISA', 'barT']
,输出:['Adam', 'Lisa', 'Bart']
代码:def chm(x):
return x[0].upper()+x[1:].lower()
map(chm,['adam','LISA':'barT'])
题目2:Python提供的sum()
函数可以接受一个list并求和,请编写一个prod()
函数,可以接受一个list并利用reduce()
求积。
代码:def prod(x,y):
return x*y
reduce(prod,[1,2,3,4,5,6])