Created
October 7, 2017 14:44
-
-
Save MichelleDalalJian/cdf4588114348d50700a30cd7d37277c to your computer and use it in GitHub Desktop.
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. 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 [email protected] Sat Jan 5 09:14:16 2008 Once you have accumulated the c…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = raw_input("Enter file:") | |
if len(name) < 1 : name = "mbox-short.txt" | |
hand = open(name) | |
hours = dict() | |
for line in hand: | |
if line.startswith("From "): | |
hour = line.split()[5].split(':')[0] | |
hours[hour] = hours.get(hour, 0) + 1 | |
for k, v in sorted(hours.items(), None): | |
print (k,v) |
luqkrzy
commented
Oct 2, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment