Skip to content

Instantly share code, notes, and snippets.

@euccas
Last active June 8, 2020 02:10
Show Gist options
  • Save euccas/dd4511c4a076b2f366c6 to your computer and use it in GitHub Desktop.
Save euccas/dd4511c4a076b2f366c6 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 co
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
hours = dict()
for line in handle.readlines():
if line.startswith('From '):
h = line.split(' ')[6].split(':')[0]
hours[h] = hours.get(h, 0) + 1
for key in sorted(hours):
print key, hours[key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment