#-*-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