title: Using OrderedDict to count instances
body: <p>I am trying to use OrderedDict() to keep track of instances of a word. I have data that is organized by day, and I want to count the number of instances of 'foo' in that day. Each line is indexed by the day. Using defaultdict gives me what I want, but, of course, without the ordering:</p>
  
  <pre><code>from collections import defaultdict
  counter = defaultdict(int)
  
  w = open('file.txt', 'r')
  y = w.readlines()
  for line in y:
      day,words = line[:6], line[14:]
      if re.search(r"foo", words):
          counter[day] += 1
  </code></pre>
  
  <p>If I use OrderedDict how can I do the same thing so I can have the data ordered the way it is read? If I use </p>
  
  <pre><code>for key, value in sorted(counter.items()):
      print(key, value)
  </code></pre>
  
  <p>Then I get the list in alphabetical order. I know I could read the days into an array and then iterate the keys based on this, however, this seems very inefficient. </p>
  
  <p>Suppose my text file looks like this:</p>
  
  <pre><code>Sep 1, 2014, 22:23 - ######: Here is a foo
  Sep 1, 2014, 22:23 - ######: Not here
  Sep 2, 2014, 19:09 - ######: foo sure
  Sep 2, 2014, 19:57 - ######: footastic
  Sep 2, 2014, 19:57 - ######: foo-king awesome
  Sep 2, 2014, 19:57 - ######: No esta aqui
  </code></pre>
  
  <p>I want my dictionary to print:</p>
  
  <pre><code>('Sep 1,', 1)
  ('Sep 2,', 3)
  </code></pre>