File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ #10.2 Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages.
2
+ #You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon.
3
+ #From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
4
+ #Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below.
5
+
6
+
7
+
8
+
9
+ name = raw_input ("Enter file:" )
10
+ if len (name ) < 1 : name = "mbox-short.txt"
11
+ handle = open (name )
12
+ d = dict ()
13
+ for line in handle :
14
+ if not line .startswith ("From " ):
15
+ continue
16
+ else :
17
+ line = line .split ()
18
+ line = line [5 ]
19
+ line = line [0 :2 ]
20
+ d [line ]= d .get (line ,0 )+ 1
21
+
22
+ lst = list ()
23
+ for value ,count in d .items ():
24
+ lst .append ((value ,count ))
25
+
26
+ lst .sort ()
27
+ for value ,count in lst :
28
+ print (value ,count )
You can’t perform that action at this time.
0 commit comments