Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # 9.4 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.
- #
- # When code is executed, this is what I am seeing at the moment ->>>>>>
- #/usr/bin/python "/Users/*****/PycharmProjects/untitled5/Week 7 - Files/Task 9.4 - Dictonaries.py"
- #gopal.ramasammycook@gmail.com 1
- #louis@media.berkeley.edu 3
- #cwen@iupui.edu 5
- #antranig@caret.cam.ac.uk 1
- #rjlowe@iupui.edu 2
- #gsilver@umich.edu 3
- #david.horwitz@uct.ac.za 4
- #wagnermr@iupui.edu 1
- #zqian@umich.edu 4
- #stephen.marquard@uct.ac.za 2
- #ray@media.berkeley.edu 1
- #
- #Process finished with exit code 0
- #
- fh = open("mbox-short.txt", "r")
- emails = dict()
- counts = 0
- value = 0
- for line in fh:
- if not line.startswith("From "):
- continue
- email = line.strip(" ").split()
- pplist = email[1].split()
- for word in pplist:
- emails[word] = emails.get(word,0) + 1
- #print emails.viewvalues()
- #print emails.viewitems()
- for keys,value in emails.items():
- print keys,value
- #for counts in emails.values():
- # if emails[counts] > counts:
- # counts = emails[counts]
- # print counts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement