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.