Python function record
map () takes a sequence of functions and a sequence, and then preserves the result returned by the function
reduce () receives a function and a sequence function result as a value, and the operation is passed from the first value of the sequence to the function, returning the result to the function again until the result is finally obtained.
The filter () filtering function receives a function and a sequence and then the function returns True and false, preserving the return true in the sequence.
def is_odd (n): return n% 2 = = 1filter (is_odd, [1, 2, 4, 5, 6, 9, 10, 15])
# results: [1, 5, 9, 15]
The sorted () sort function can customize the comparison function.
pp = [2,10,-5,100,25,-50]p = sorted (PP) print P
You can also define a comparison function like this
DEF CMP (x, y): if x>y: return-1 if x<y: return 1 return 0pp = [2,10,-5,100,25,-50]p = sorted ( PP,CMP) Print P
Lambda anonymous function Call method Lambda x:x * x
Python Learning Record