Created
August 16, 2015 04:32
-
-
Save KKarthikeya/ff08a34c3d0c6cac28b7 to your computer and use it in GitHub Desktop.
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…
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
mails = dict() | |
for line in open( raw_input("Enter File Name:")): | |
words = line.strip().split() | |
if len(words) == 0 and len(words)<2: | |
continue | |
if words[0] == 'From': | |
hours = words[5].split(':') | |
if hours[0] not in mails: | |
mails[hours[0]] = 1 | |
else: | |
mails[hours[0]] += 1 | |
mail_list = list() | |
for key,mail in mails.items(): | |
mail_list.append((key,mail)) | |
mail_list.sort() | |
for key,val in mail_list: | |
print key,val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment