Advertisement
dvdjaco

9.5

Feb 18th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. # #!/usr/bin/python
  2. #
  3. # By dvdjaco
  4. # Exercise 9.5
  5. #
  6.  
  7. f = raw_input('Enter a file name: ')
  8.  
  9. try:
  10.     fhand = open(f)
  11. except IOError, err :
  12.         print "Error opening file", f
  13.         print "Error was:", err
  14. d = dict()
  15.  
  16. # build a dictionary with all domain names and count the number of messages
  17. # sent from each one
  18. for line in fhand:
  19.     words = line.split()
  20.     if len(words) == 0 or words[0] != 'From' or words[1].find('@') == -1: continue
  21.     address = words[1]
  22.     domain = address[address.find('@') + 1:]
  23.     d[domain] = d.get(domain,0) + 1
  24.  
  25. print d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement