Use the map() function to change the non-standard English name input by the user into a standard name with the first letter in uppercase and other lowercase letters. Input: ['adam', 'LISA', 'barT'], output: ['Adam', 'Lisa', 'Bart'].
1 def cg(name):2 return name[0].upper()+name[1:].lower()3 L = ['adam', 'LISA', 'barT']4 print map(cg,L1)
Write a prod()
function that can accept a list And use reduce()
to find the product.
1 def prod(num1,num2):2 return num1*num23 L = [3,7,5,9]4 print reduce(prod,L)
The above is the detailed content of Python 2 map() reduce() function usage explanation. For more information, please follow other related articles on the PHP Chinese website!