Skip to content

Commit 53b8274

Browse files
Add files via upload
1 parent 3d84633 commit 53b8274

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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)

0 commit comments

Comments
 (0)