Map
Iterate through the sequence, manipulate each of these elements, and finally get a new sequence
LST =[1,2,3,4]
def fun (ARG):
Return arg+10
New_lst = Map (fun,lst)
def fun2 (A1,A2):
Return A1+A2
lst01 = [11,22,33]
lst02 = [A]
Map (func2,lst01,lst02) #序列的长度需要一致
or map (lambda a1,a2,a3:a1+a2,lst01,lst02)
#################################################################
Filter
There are two parameters, the first parameter is a function or none the second argument is a sequence
Receives a function or none, returns a collection of elements that match the criteria
LST = [1,2,3,4,5,0]
Print filter (None,li) # Iterates through all the elements and filters out the elements that are false for the Boolean value, at which point the boolean is the true element.
Output of elements greater than 3
Print filter (lambda a:a>3,lst)
#################################################################
Reduce
Accumulates the elements within the sequence, returning a result
# The first parameter of reduce, the function must have two parameters
# The second parameter of reduce, the sequence to loop
# The third parameter of reduce, the initial value
Li = [11, 22, 33]
result = reduce (lambda arg1, Arg2:arg1 + arg2, Li)
# The first parameter of reduce, the function must have two parameters
# The second parameter of reduce, the sequence to loop
# The third parameter of reduce, the initial value
#################################################################
Yield generator
Remember the last action, the next time you execute, you can continue to execute
def fun ():
Yield 1
Yield 2
Yield 3
For I in Fun ():
Print I
Results:
1
2
3
Custom generators:
Def myrange (num):
Seed =0
While True:
If Seed>=num:
Break
Seed+=1
Yield seed
For I in myrange (10):
Print I
This article is from the "'ll Notes" blog, so be sure to keep this source http://timesnotes.blog.51cto.com/1079212/1715266
Python Learning note-day04-Part III (built-in function, Map,filter,reduce,yield)