Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # #!/usr/bin/python
- #
- # By dvdjaco
- # Exercise 9.5
- #
- f = raw_input('Enter a file name: ')
- try:
- fhand = open(f)
- except IOError, err :
- print "Error opening file", f
- print "Error was:", err
- d = dict()
- # build a dictionary with all domain names and count the number of messages
- # sent from each one
- for line in fhand:
- words = line.split()
- if len(words) == 0 or words[0] != 'From' or words[1].find('@') == -1: continue
- address = words[1]
- domain = address[address.find('@') + 1:]
- d[domain] = d.get(domain,0) + 1
- print d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement