Exercises 1 is embedded in the Dictionaries page so you must go there and find it if you did not do it while reading the page.
Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for lines that start with "From", then look for the third word and keep a running count of each of the days of the week. At the end of the program print out the contents of your dictionary (order does not matter).
Sample Line:
From [email protected] Sat Jan 5 09:14:16 2008Sample Execution:
python dow.pyEnter a file name: mbox-short.txt{'Fri': 20, 'Thu': 6, 'Sat': 1}Submit the program file with the name '10-2.py' once the program is thoroughly tested.
Write a program to read through a mail log, build a histogram using a dictionary to count how many messages have come from each email address, and print the dictionary.
Enter file name: mbox-short.txt{'[email protected]': 1, '[email protected]': 3,'[email protected]': 5, '[email protected]': 1,'[email protected]': 2, '[email protected]': 3,'[email protected]': 4, '[email protected]': 1,'[email protected]': 4, '[email protected]': 2,'[email protected]': 1}Submit the program file with the name '10-3.py' once the program is thoroughly tested.
Add code to the above program to figure out who has the most messages in the file.
After all the data has been read and the dictionary has been created, look through the dictionary using a maximum loop (see Chapter 5 if you need a refresher on it) to find who has the most messages and print how many messages the person has.
Enter a file name: mbox-short.txt[email protected]5
Enter a file name: mbox.txt[email protected]195
Submit the program file with the name '10-4.py' once the program is thoroughly tested.
This program records the domain name (instead of the address) where the message was sent from instead of who the mail came from (i.e., the whole email address). At the end of the program, print out the contents of your dictionary.
python schoolcount.pyEnter a file name: mbox-short.txt{'media.berkeley.edu': 4, 'uct.ac.za': 6, 'umich.edu': 7,'gmail.com': 1, 'caret.cam.ac.uk': 1, 'iupui.edu': 8}Submit the program file with the name '10-5.py' once the program is thoroughly tested.
Email addresses above are visible in the downloaded version of the book. They are hidden here to protect the addresses from discovery by spam bots.