I need to search for the hours of the day that each email was sent, then I need to create a dictionary from those. Then I need to print the dictionary at the end with the count of how many times an email was sent at each hour.
Here is a sample of how it should look:
Enter a file name: mbox-short.txt
So basically I am stuck on how to search for the hours and add them to the dictionary. Can anyone help me please? Thank you very much!
import string fhandler = open('mbox-short.txt') counts = dict() for line in fhandler: emails = line.split('@') for email in emails: counts[email] = counts.get(email, 0) + 1 lst = list() for key, val in counts.items(): lst.append( (val, key) ) lst.sort(reverse=True) for val, key in lst[:1] : print key, val