Tag: Lam class number length defines sum expression span TE
Lambda is used to define a function
Common functions:
def multiply (x, y): return x * y
Use lambda to override the above functions:
Lambda x, y:x * y
The lambda function consists of three parts:
1. Lambda keyword
2. The parameter of the partition is the parameter in the normal function, followed by a :
3. Function body, which is the function body in normal function
Some chestnuts:
# calculates the average of the individual lists in the numbers list, and then returns them to a list numbers = [[The] " ["]. >63, Panax Notoginseng,],[, each, each, each, the list (map (lambda x:sum (x)/len (x), numbers))
Results: [57.0, 58.2, 50.6, 27.2]
# filter out cities with a city name less than 10 cities = [ " new York city " , " los Angeles " , " chicago " , mountain View Span style= "COLOR: #800000" > ", " denver ", " Boston " ]short_cities = List ( Filter (lambda x:len (x) < ten, cities)
Result: ['Chicago'Denver'Boston ' ]
PYTHON-LAMBDA-expression