The difference between map,filter and reduce functions in Python

Source: Internet
Author: User

The Map,filter and reduce function arguments in Python must all be a function and a parameter.

The difference is:


When the map executes, a function is typically executed once for each element in the parameter or list, returning a list of the functions that were executed after the individual parameters. Map (function, sequence[, sequence, ...])-> list


Filter is the input of the list of parameters filtered, the general input function is a predicate function, returns a Boolean value, 1, the list of parameters will return, 0, it will not return. Finally returns a collection of arguments consisting of a Boolean value of 1.

Filter (function or None, sequence)-> list, tuple, or string

Reduce sums up the elements of the parameter list, and the input function typically requires two parameter values, and if you do not enter the initial parameter, the first two elements of the list are called as initial parameters, and the return value is evaluated as the next call's input parameter and the third element, and so on.

Reduce (function, sequence[, initial])-> value

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.