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

Python 2 map() reduce() function usage explanation

巴扎黑
Release: 2017-07-24 16:52:20
Original
1814 people have browsed it

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)
Copy after login
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)
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template