First, what is anonymous function
Anonymous functions as the name implies, it does not have the function name that can be used to invoke, like a normal function, and the definition of an anonymous function is concise with a lambda as the definition keyword, followed by a function parameter separated by a colon is the function body of the function. The function body of an anonymous function can only perform some simple calculations and is generally disposable.
Second, the application of anonymous function
1T1= (('a'),('b'))2T2= (('C'),('D'))3Func=LambdaX,Y:[{I,J} forI,jinchzip (x, y)]4 Print(func (t1,t2))5--------------------------------------------------------------------------------------6[{'a':'C'},{'b':"'D}]View Code
Three, dictionary derivation formula
Dictionary derivation like List derivation, format {key:value for key in Dict}, dictionary derivation generally requires a different dictionary
Four, set deduction formula
Set deduction and list derivation are similar, format {i for I in range (10)}
Five, the dictionary derivation type supplement
A list derivation can use multiple for loops and can filter elements with an IF condition statement
1l=[['Tom','Billy','Jefferson','Andrew','Wesley','Steven','Joe'],2['Alice','Jill','Ana','Wendy','Jennifer','Sherry','Eva']]3New_l=[j forIinchL forJinchIifJ.count ('e') >=2]4 Print(new_l)View Code
anonymous function of Python function