title: Count distinct IDs for each year in Python
body: <p>Suppose we have file like (first column refers to ID number and the second column to year):</p>
  
  <pre><code>1|2015
  1|2015
  1|2015
  2|2015
  2|2015
  2|2015
  3|2014
  3|2014
  4|2014
  4|2014
  5|2013
  </code></pre>
  
  <p>Task is to count how many IDs are there for each year. For example in our case the output file should be:</p>
  
  <pre><code>2015|2
  2014|2
  2013|1
  </code></pre>
  
  <p>What is the most appropriate programming structure to count these frequencies? My initial attempt is pasted below. (Current code prints only the number of distinct IDs.)</p>
  
  <pre><code>tmp_id = ''
  counter = 0
  with open('test.txt') as my_file:
      for line in my_file:
          id, year = line.strip().split('|')
          if (id != tmp_id):
              counter = counter + 1
          tmp_id = id
  print(counter)
  </code></pre>