Tuples are essential to understanding dictionaries so the information in this module is presented first, but the information in the dictionaries module greatly simplifies the following exercises so it is best to view those videos and read that information before attempting exercises 9-1, 9-2, and 9-3.
Revise a previous program as follows: Read and parse the "From" lines and pull out the addresses from the line. Count the number of messages from each person using a dictionary.
After all the data has been read, print the person with the most commits by creating a list of (count, email) tuples from the dictionary. Then sort the list in reverse order and print out the person who has the most commits.
Sample Line:From [email protected] Sat Jan 5 09:14:16 2008Enter 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 '9-1.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.
This program counts the distribution of the hour of the day for each of the messages. You can pull the hour from the "From" line by finding the time string and then splitting that string into parts using the colon character. Once you have accumulated the counts for each hour, print out the counts, one per line, sorted by hour as shown below.
Sample Execution:
python timeofday.pyEnter a file name: mbox-short.txt04 306 107 109 210 311 614 115 216 417 218 119 1Submit the program file with the name '9-2.py' once the program is thoroughly tested.
Write a program that reads a file and prints the letters in decreasing order of frequency. Your program should convert all the input to lower case and only count the letters a-z. Your program should not count spaces, digits, punctuation, or anything other than the letters a-z. Find text samples from several different languages and see how letter frequency varies between languages. Compare your results with the tables at wikipedia.org/wiki/Letter_frequencies.
Submit the program file with the name '9-3.py' once the program is thoroughly tested.