forked from dunossauro/Py.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapreduce.py
117 lines (75 loc) · 2.03 KB
/
mapreduce.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import operator, os
listas = ["Michelle", "Eduardo", "Will"] #De strings
listan = [4, 6, 8, 10] #De Numero
listaf = [4.78, 6.78, 8.78, 10.78] #De float
listac = ["M","E","W"] #De Char
listam = ["Gabriel", 654, 4.78, "M"] #Mista
lamb = lambda x: x*2 #Funcao usada no map que multiplica por 2
os.system("clear")
print "==== Valores insediros ===="
print listas;print listan; print listaf; print listac; print listam
print "==== Valores de MAP(elevando a 2);SORT ===="
"""
Implementacao do MAP e SORT
"""
#resposta do map de strings
rmaps = map(lamb, listas)
print sorted(rmaps)
#resposta do map de numbers
rmapn = map(lamb, listan)
print sorted(rmapn)
#resposta do map de floats
rmapf = map(lamb, listaf)
print sorted(rmapf)
#resposta do map de char
rmapc = map(lamb, listac)
print sorted(rmapc)
#resposta do map misto
rmapm = map(lamb, listam)
print sorted(rmapm)
"""
Implementacao do REDUCE dos valores insediros
"""
print"==== Valores do Reduce (iserido (soma)) ===="
#Resposta do reduce de string
rreds = reduce(operator.add, listas)
print rreds
#Resposta do reduce de Number
rredn = reduce(operator.add, listan)
print rredn
#Resposta do reduce de Float
rredf = reduce(operator.add, listaf)
print rredf
#Resposta do reduce de char
rredc = reduce(operator.add, listac)
print rredc
#Problema: Nao podemos concatenar inteiros e strings
"""
#Resposta do reduce misto
rredm = reduce(operator.add, listam)
print rredm
"""
print "FAIL: MISTO"
"""
Implementacao do REDUCE dos valores mapeados
"""
print"==== Valores do Reduce (mapeados (soma)) ===="
#Resposta do reduce de string
rreds = reduce(operator.add, rmaps)
print rreds
#Resposta do reduce de Number
rredn = reduce(operator.add, rmapn)
print rredn
#Resposta do reduce de Float
rredf = reduce(operator.add, rmapf)
print rredf
#Resposta do reduce de char
rredc = reduce(operator.add, rmapc)
print rredc
#Problema: Nao podemos concatenar inteiros e strings
"""
#Resposta do reduce misto
rredm = reduce(operator.add, listam)
print rredm
"""
print "FAIL: MISTO"