Advertisement
dvdjaco

10.2

Feb 18th, 2012
205
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 10.2
  5. #
  6.  
  7. fname = raw_input('Enter a filename: ')
  8.  
  9. try:
  10.     f = open(fname)
  11. except err:
  12.     print "There was an error: ", err
  13.    
  14. d = dict()
  15.    
  16. for line in f:
  17.     words = line.split()
  18.     if len(words) == 0 or words[0] != 'From' or words[1].find('@') == -1: continue
  19.     time = words[5]
  20.     hour = time.split(':')[0]
  21.     d[hour] = d.get(hour,0) + 1
  22.  
  23. lst = list()
  24. for hour, count in d.items(): lst.append( (hour, count) )
  25. lst.sort()
  26. for hour,count in lst: print hour, count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement