title: Chapter 9 Exercise 2 Python for Everybody problem with dictionary and loops
body: <p>I'm not sure why I keep the wrong answer. I first found the days through for line in hand loop and then added key and value through dictionary, yet I don't get the output that I thought about. Could you please help me? than you!</p>
  <p>Exercise 2: Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for lines that start with “From”, then look for the third word and keep a running count of each of the days of the week. At the end of the program print out the contents of your dictionary (order does not matter).</p>
  <p>Sample Line:</p>
  <p>From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008</p>
  <p>Sample Execution:</p>
  <p>python dow.py</p>
  <pre><code>Enter a file name: mbox-short.txt
  {'Fri': 20, 'Thu': 6, 'Sat': 1}
  </code></pre>
  <p>Here is my code</p>
  <pre><code>#mbox-short.txt
  fname = input(&quot;Enter a file name: &quot;)
  hand = open(fname)
  
  counts = dict()
  for line in hand:
      line = line.rstrip()
      if not line.startswith('From '): continue
      words = line.split()
      words = words[2]
      for word in words:
          if word not in counts:
              counts[word] = 1
          else:
              counts[word] += 1
  
  print(counts)
  </code></pre>
  <p>output</p>
  <pre><code>{'S': 1, 'a': 1, 't': 1, 'F': 20, 'r': 20, 'i': 20, 'T': 6, 'h': 6, 'u': 6}
  </code></pre>