Some uses and summaries of Python lambda and startwith.

Source: Internet
Author: User

Recently in the analysis of the data, with some simple filtering, but also learned, lambda and startwith some usage, write a memo below, first understand lambda. This is a small usage of a similar function, which can be used in conjunction with the filter:

>>> Xiaoluo = lambda x,y:x+y>>> print Xiaoluo ($) 3>>> print Xiaoluo (3,4) 7

Take a look at the result: equals the meaning of Xiaoluo = lambda x,y:print x+y.

>>> A = [1,2,3]>>> filter (lambda x:x<2,a) [1]

Look at the Startwith is also a filter thing, just at the beginning of the string, in case we haven't used the re:

#!/usr/bin/env pythonimport OSF = open ('/etc/passwd ', ' r ') lines = F.readlines () for line in Lines:if line.startswith ("Ro OT "): Print Line

return Result:

Root:x:0:0:root:/root:/bin/bash

Summary: The use of these two tools, although good, but there are certain limitations, later after using the RE is not very useful,

This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1619241

Some uses and summaries of Python lambda and startwith.

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.