-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut36.AnonymousORLambdaFunctions.py
80 lines (53 loc) · 1.62 KB
/
tut36.AnonymousORLambdaFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def add(a,b):
return a+b
minus=lambda x,y:x-y
print(add(1,2),minus(3,4)) #output : 3 -1
#..........................................................................
#sorting with respect to first element
def list1_first(list1):
return list1[0]
list1=[[111,9],[9,6],[8,34]]
list1.sort(key=list1_first)
print(list1)
#........
list1=[[111,9],[9,6],[8,34]]
list1.sort(key=lambda x:x[0])
#..........................................................................
#sorting with respect to first element
def list1_first(list1):
return list1[1]
list1=[[111,9],[9,6],[8,34]]
list1.sort(key=list1_first)
print(list1)
#........
list1=[[111,9],[9,6],[8,34]]
list1.sort(key=lambda x:x[1])
print(list1)
#...................................................................................
#sorting with respect to second element
# some self practiced
#lambda functions
def sq(num):
return num*num
def cb(num):
return num*num*num
def powFour(num):
return num*num*num*num
ssp=lambda x:x*x
numx=4
print(sq(numx))
print(cb(numx))
print(powFour(numx))
print(ssp(numx))
#.................................................................................................................
def add(x,y):
return x+y
subtract=lambda x,y:x-y
numx=10
numy=11
print(add(numx,numy))
print(subtract(numx,numy))
print((lambda x,y:x*y)(numx,numy) )
print((lambda x,y:x/y)(numx,numy) )
print((lambda x,y:x**y)(numx,numy) )
#.................................................................................................................