
10.2
By:
dvdjaco on
Feb 18th, 2012 | syntax:
Python | size: 0.54 KB | hits: 22 | expires: Never
# #!/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