python basis of a day16 anonymous function

the Add DEF (X, Y): 
return X + Y

the Add the lambda = X, Y: X + Y
Print (the Add (1,2))

DIC = { 'K1': 10, 'K2': 100, 'K3': } 30
DEF FUNC (Key):
return DIC [Key]
Print (max (DIC, FUNC = Key)) # determines the maximum value based on the return, the return value of the result parameter is the maximum that
print (max (dic, key = lambda key : DIC [Key]))
max ([1,2,3,4,5, -6, -7], Key = ABS)

RET = Map (ABS, [- 1,2,-3,4])
for in RET I:
Print (I)

DEF FUNC (X):
return X ** 2
RET = Map (FUNC, [- 1,2,-3,4])
for I in RET:
Print (I)

RET = Map ( X the lambda: X ** 2, [- 1,2,-3,4])


DEF FUNC (X):
return X> 10

RES = filter (FUNC, [5,8,11,9,15])
for I RES in:
Print (I)


min max Map the sorted filter - the lambda

the lambda P = D: P 2 *
T = the lambda P: P. 3 *
X = 2
X = D (X) = #x is. 4
X = T (X) = 12 is #x is
X = D (X) = #x is 24
Print (X)

RET = ZIP ((( 'A'), ( 'B')), (( 'C'), ( 'D')))
RET = Map (the lambda T: {T [0]: T [ . 1]}, RET)
Print (List (RET))

two existing tuple (( 'a'), ( 'b')), (( 'c'), ( 'd')),
use in python generating a list of anonymous function [{ 'A': 'C'}, { 'B': 'D'}]

max min the sorted filter Map
anonymous function built-in function ==
ZIP
RET = ZIP ((( 'A'), ( ' B ')), ((' C '), (' D ')))
RES = Map (the lambda TUP: {TUP [0]: TUP [. 1]}, RET)
Print (List (RES))

DEF Multipliers ( ):
return [the lambda X: X I * for I in Range (. 4)]
Print ([m (2) for m in Multipliers ()])



Guess you like

Origin www.cnblogs.com/wang-tan/p/11082291.html