Advertisement
Guest User

dictonary

a guest
Jul 24th, 2016
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #
  2. # 9.4 Write a program to read through the mbox-short.txt and figure out who has
  3. # the sent the greatest number of mail messages. The program looks for 'From ' lines
  4. # and takes the second word of those lines as the person who sent the mail. The program
  5. # creates a Python dictionary that maps the sender's mail address to a count of the number
  6. # of times they appear in the file. After the dictionary is produced, the program reads
  7. # through the dictionary using a maximum loop to find the most prolific committer.
  8. #
  9.  
  10.  
  11. # When code is executed, this is what I am seeing at the moment ->>>>>>
  12. #/usr/bin/python "/Users/*****/PycharmProjects/untitled5/Week 7 - Files/Task 9.4 - Dictonaries.py"
  13. #gopal.ramasammycook@gmail.com 1
  14. #louis@media.berkeley.edu 3
  15. #cwen@iupui.edu 5
  16. #antranig@caret.cam.ac.uk 1
  17. #rjlowe@iupui.edu 2
  18. #gsilver@umich.edu 3
  19. #david.horwitz@uct.ac.za 4
  20. #wagnermr@iupui.edu 1
  21. #zqian@umich.edu 4
  22. #stephen.marquard@uct.ac.za 2
  23. #ray@media.berkeley.edu 1
  24. #
  25. #Process finished with exit code 0
  26.  
  27.  
  28. #
  29.  
  30.  
  31. fh = open("mbox-short.txt", "r")
  32. emails = dict()
  33. counts = 0
  34. value = 0
  35.  
  36. for line in fh:
  37. if not line.startswith("From "):
  38. continue
  39. email = line.strip(" ").split()
  40. pplist = email[1].split()
  41. for word in pplist:
  42. emails[word] = emails.get(word,0) + 1
  43.  
  44. #print emails.viewvalues()
  45. #print emails.viewitems()
  46.  
  47. for keys,value in emails.items():
  48. print keys,value
  49.  
  50.  
  51.  
  52. #for counts in emails.values():
  53. # if emails[counts] > counts:
  54. # counts = emails[counts]
  55. # print counts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement