Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Created August 16, 2015 04:32
Show Gist options
  • Save KKarthikeya/ff08a34c3d0c6cac28b7 to your computer and use it in GitHub Desktop.
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…
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