Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # #!/usr/bin/python
- #
- # By dvdjaco
- # Exercise 9.4
- #
- 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 email addresses 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
- d[words[1]] = d.get(words[1],0) + 1
- # find who sent max messages
- maxmessages = None
- for sender in d:
- if maxmessages is None or d[sender] > maxmessages:
- maxmessages = d[sender]
- maxsender = sender
- print d
- print maxsender, "has sent", maxmessages, "messages"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement