Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # #!/usr/bin/python
- #
- # By dvdjaco
- # Exercise 10.2
- #
- fname = raw_input('Enter a filename: ')
- try:
- f = open(fname)
- except err:
- print "There was an error: ", err
- d = dict()
- for line in f:
- words = line.split()
- if len(words) == 0 or words[0] != 'From' or words[1].find('@') == -1: continue
- time = words[5]
- hour = time.split(':')[0]
- d[hour] = d.get(hour,0) + 1
- lst = list()
- for hour, count in d.items(): lst.append( (hour, count) )
- lst.sort()
- for hour,count in lst: print hour, count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement