-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_reduce_filter_lamda.py
89 lines (42 loc) · 1.21 KB
/
map_reduce_filter_lamda.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
81
82
83
# >>>>>>>>>>>>>>>>>>>>>>>>>>>lamda<<<<<<<<<<<<<<<<<<<<<<
function = lambda x,y:x+y
# possible
functionBool = lambda x,y:x==y
# possible
testCalculation=function(2,3)
testboolCheck = functionBool(2,2)
print(testCalculation)
print(testboolCheck)
numberlist1=[1,2,3,4,5]
numberlist2=[10,20,30,40,50,51]
testtuplelist=list(zip(numberlist1,numberlist2))
print(testtuplelist)
print(testtuplelist[0][1])
testtupleZipObject=zip(numberlist1,numberlist2)
result = map(lambda x,y:x+y,numberlist1,numberlist2)
print(list(result))
# [11, 22, 33, 44, 55]
#>>>>>>>>>>>>>>>>MAP<<<<<<<<<<<<<<<<<
# def fahrenheit(T):
# return ((float(9)/5)*T + 32)
# def celsius(T):
# return (float(5)/9)*(T-32)
someTemperature = [39.2,38.0,41.0,30]
resultlist=map(lambda x:(float(9)/5)*x + 32,someTemperature)
print(list(resultlist))
# 5
# True
# [102.56, 100.4, 105.8, 86.0]
#>>>>>>>>>>FILTER<<<<<<<<<<<<<<
somenumbers = [2,7,11,13,19,20]
oddnumberlist=filter(lambda x: x%2==0,somenumbers)
print(list(oddnumberlist))
# output
# [2, 20]
#>>>>>>>>>>>REDUCE<<<<<<<<<<<<<
some_numbers_to_add = [2,7,13,100]
import functools
summation = functools.reduce(lambda x,y:x+y,some_numbers_to_add)
print(summation)
# output
# 122