Functional Programming Tools: filter and reduce

Source: Internet
Author: User

#-*-coding:utf-8-*-#python#Xiaodeng#Functional Programming Tools: filter and reduce#in Python built-in functions, the map function is the simplest built-in function algebra for tools such as functional programming#functional Programming Meaning:#a programming paradigm, that is, how to write a program methodology, is a programming idea. #unable to give an accurate definition#the programmatic style of functional programming emphasizes expression calculations, rather than executing commands. #Common Function-type programming#Filter: Filters out some elements based on a test function#Reduce: Applies a function to each pair of elements and runs to the final result, both of which return an iterative object#page: 523#Filter , filteringPrintList (Filter (Lambdax:x>0), Range ( -5,5)))#[1, 2, 3, 4]#the above is equivalent to:res=[] forXinchRange ( -5,5):    ifX>0:res.append (x)#Why is there no indentation at print res? Because res his definition is shelf, if print is not shelf, then there must be a difference between the output results        PrintRes#[1, 2, 3, 4]#Reduce function#A pair of element 22 runs to get its resultPrintReduce (LambdaX,y:x+y), [1,2,3,4])#TenPrintReduce (LambdaX,y:x*y), [1,2,3,4])# -#General design principles for writing functions:1function as small as possible, self-contained, with a single, unified use2) Other parts, such as access parameters and return values, communicate with each other-functions of communication

Functional Programming Tools: filter and reduce

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.