-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWhatIsLambda.py
77 lines (48 loc) · 1.34 KB
/
WhatIsLambda.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
def squareNumber(n):
if type(n) == int:
return n*n
else:
return 0
def checkForEven(n):
if type(n) is not int:
return
return n%2 ==0
def add(x, y):
return x+y
print(squareNumber(10))
# if you want to pass a list as a parameter, then will the above function (add()) block will support?
# NO
sampleList =[1,2,3,4,5]
outputList = []
for i in sampleList:
outputList.append(squareNumber(i))
print(outputList)
outputList2 = []
for i in sampleList:
if checkForEven(i):
outputList2.append(i)
print("output list 2 is ", outputList2)
# ===================================================
evenNum = list(filter(lambda x: x%2 ==0, sampleList))
print(evenNum)
sqNum = list(map(squareNumber, sampleList))
print("sqNum is .. ", sqNum)
globalExample = map(lambda x, y: (x+y, x-y, x*y), [10, 20, 30, 40],[5,10,15,20])
globalExample = map(lambda x, y: (x+y, x-y, x*y), [10, 20, 30, 40],[5,10,15,20])
print(list(globalExample))
# List of strings
l = ['sat', 'bat', 'cat', 'mat']
opList = []
for i in l:
opList.append(list(i))
print(opList)
map(list, l)
# class calculator:
# add = lambda x,y: x+y
# sub = lambda x,y: x-y
# mul = lambda x,y: x*y
# def add(a,b):
# return a+b
# print("here you go ...")
# cal = calculator()
# print(calculator.add(10,5))