Home >Backend Development >Python Tutorial >Python 2 map() reduce() function usage explanation

Python 2 map() reduce() function usage explanation

巴扎黑
巴扎黑Original
2017-07-24 16:52:201831browse

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)
View Code

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)
View Code

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn