-
-
Save illucent/fe7a54036e6d85ac4fb3 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 [email protected] Sat Jan 5 09:14:16 2008 Once you have accumulated the counts…
This file contains hidden or 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