anonymous function of Python function

Source: Internet
Author: User

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

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.