[Python Basics]python built-in functions Map/reduce/filter

Source: Internet
Author: User

Python built-in function map/reduce/filter These three functions are handy, very cool.

filter () function: The filter function is equivalent to filtering, calling a Bool_func (a method that returns only bool type data) to iterate through the elements in each sequence.

Returns the sequence of elements that bool_func the result to true (note what the sequence means) http://blog.csdn.net/bolike/article/details/19997465 sequence reference </a>

If the filter parameter value is the None,list parameter, all elements that are false are deleted.

map () function :

Iterates through all the elements in the sequence, returns a sequence after processing

Reduce function:

Func takes two arguments, so each time a pair is taken (the previous result and the next element), a result is returned.

The advanced function, which is the function as a parameter, then make a mess.

I am not very good with these three functions, the only way is to use more, with the use of the habit, like the original I am not accustomed to using the list to generate the formula.

Later, the discovery list generation is particularly hassle-free, now don't be unhappy. hahaha, let's use these high-level functions together to make your code more concise and more readable.

[Python Basics]python built-in functions Map/reduce/filter

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.