Files and Dictonaries
Doing coursera ( just practice) and no matter what I try with this question I cannot get it to give me the max for the key/value pair that appears most. here is the question. Write a program to read through the mbox-short.txt and figure out who has the sent the greatest number of mail messages. The program looks for 'From ' lines and takes the second word of those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender's mail address to a count of the number of times they appear in the file. After the dictionary is produced, the program reads through the dictionary using a maximum loop to find the most prolific committer. So far I can print all the email's only as well as the dict() the last part of the question just does not seem to be anywhere in this chapter or previous.. not even sure what I did ...lol my code. fname = input("Enter file name: ") fh = open(fname) count = dict() for handle in fh: if not handle.startswith("From "): continue handle = handle.rstrip() words = handle.split() for word in words: count[word] = count.get(word,0) + 1 print(words[1])