-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython
40 lines (34 loc) · 800 Bytes
/
python
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
1;2016-01-01;1;20
2;2016-02-10;2;41
3;2016-02-21;1;7
4;2016-03-07;3;93
5;2016-04-05;1;15
6;2016-04-06;2;18
7;2016-04-11;3;27
8;2016-06-24;1;11
9;2016-06-25;2;14
#!/usr/bin/python
import sys
def map():
for line in sys.stdin:
data = line.split(';')
machine_id = data[2]
time = data[3]
print machine_id + '\t' + time
if __name__ == '__main__':
map()#!/usr/bin/python
# coding=utf-8
import sys
from collections import defaultdict
def reduce():
my_dict = defaultdict(set)
for pipe in sys.stdin:
line = pipe.strip()
machine = line.split('\t')[0]
time = line.split('\t')[1]
#add the key to the dictionary, adding or incrementing the time value
my_dict[machine].add(time + my_dict[machine])
for key in my_dict:
print key + '\t' + s
if __name__ == '__main__':
reduce()