Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 885c353

Browse files
Create Assignment 10.2.py
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. 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. From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below.
1 parent fe9fc3d commit 885c353

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎Assignment 10.2.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name = input("Enter file:")
2+
file = open(name)
3+
counts = dict()
4+
5+
for line in file:
6+
if line.startswith('From ') :
7+
words = line.split()
8+
time = words[5]
9+
hours = time[:2]
10+
counts[hours] = counts.get(hours,0) + 1
11+
12+
for key, val in sorted(counts.items()):
13+
print (key, val)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /