For Python version 2.x
1. Lambda functions
1 Lambda y 2 print func (2, 4)
Lambda generates a function object, the parameter is x, Y, and returns X+Y.
2. Map () function
1 RTN = map ((Lambda x:x*3), [1, 2, 3, 4, 5, 6])2print RTN
Map is a python built-in function, the first parameter is a function, the second argument is a sequence. The first function acts on each element of the sequence and places the result in the sequence Rtn.
3. Reduce () function
RTN = reduce ((lambda x, y:x + y), [1, 3, 5, 7, 9])print RTN
Reduce is also a python built-in function, with two parameters, the first parameter is a function, and the second is a sequence. The first two elements of the sequence are first used as the two parameters of the lambda function, the return value as the lambda parameter, the next element of the sequence (that is, the 3rd element) as the second parameter of the lambda, which in turn acts on the entire sequence.
4. Filter () function
def isodd (n): if n% 2 = = 0 :return False Else :return = Filter (isodd, [1, 2, 3, 4, 5, 6])print rtntype (RTN)
The filter function is also a python built-in function. The first parameter of the filter function is a function that filters the data, and the second parameter is the data to be filtered.
IsOdd judgment is not the cardinality, is the return true, not the return false. The filter is based on the result returned by the IsOdd function to decide whether to keep the number, and true to keep it. This will play a role in screening.
Summarize:
Lambda functions
Map () function
Reduce () function
Filter () function
Python function object