title: Invalid Output for Coursera Python Assignment
body: <p>I'm doing the Coursera Python for Everybody stream and I'm stuck on Assignment 10.2. I'm getting invalid output for it. Here is what the assignment asks:</p>
  
  <blockquote>
    <p>Write a program to read through the mbox-short.txt and figure out the
    distribution by hour of the day for each of the messages. You can pull
    the hour out from the 'From ' line by finding the time and then
    splitting the string a second time using a colon.</p>
  
  <pre><code>From stephen.marquard@uct.ac.za Sat Jan  5 09:14:16 2008
  </code></pre>
    
    <p>Once you have accumulated the counts for each hour, print out the
    counts, sorted by hour as shown below.</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>name = raw_input("Enter file:")
  if len(name) &lt; 1 : name = "mbox-short.txt"
  handle = open(name)
  counts = dict()
  lst = list()
  
  for line in handle:
      line = line.rstrip()
      if not line.startswith('From '):
          continue
      words = line.split()
      words = words[5]
      words = words.split(":")
      for word in counts:
          counts[word] = counts.get(word, 0) + 1
  
  lst = list()
  for key, val in counts.items():
      lst.append((key, val))
  
  lst.sort()
  
  print lst
  </code></pre>
  
  <p>Let me know what I'm doing wrong. Any advice or hint is appreciated.</p>