File tree 1 file changed +24
-0
lines changed
Python_Data_Structures_assignments
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ #program to read through the mbox-short.txt and figure out the
2
+ #distribution by hour of the day for each of the messages.
3
+ name = input ("Enter file:" )
4
+ if len (name ) < 1 : name = "mbox-short.txt"
5
+ handle = open (name )
6
+ keyword = 'From'
7
+ c_hour = dict ()
8
+ for lin in handle :
9
+ words = lin .split ()
10
+ #print(words)#debugging
11
+ if keyword in words :
12
+ #print(words[5])
13
+ date = words [5 ].split (':' )
14
+ hour = date [0 ]
15
+ c_hour [hour ]= c_hour .get (hour ,0 )+ 1
16
+ #print(c_hour)#debugging
17
+ #print(c_hour.items())#debugging
18
+ temp = list ()
19
+ for k ,v in c_hour .items ():#iterate the tuples inside list
20
+ temp .append ((k ,v ))#append the values of k and v to temp list
21
+
22
+ temp = sorted (temp )#sort the temp list (of tuples)
23
+ for i ,j in temp :#iterate through the temp list and print the value pairs
24
+ print (i ,j )
You can’t perform that action at this time.
0 commit comments