title: How do I loop through the rows in a column and count them using Python?
body: <p>I am trying to loop through column in an access table using Python. The column I have is sorted ascending. </p>
  
  <p>I am trying to loop though the rows and when the value in the column changes, I want to get count of of all those values. In the example column below, the first group of values I want to count are the <code>M1</code>'s. When the next row changes to <code>M21</code>, I want to count the <code>M21</code>'s until it changes to <code>M23b</code> and so on. </p>
  
  <p>I don't want to use an <code>if</code>/<code>else</code> statement, because there are a few hundred different possible values. I played around with the <code>groupby</code> function in the <code>itertools</code> module, but I haven't been able to solve the syntax to work in my example. I also tried a silly loop doing something like <code>if row != row.next(): do_something</code> but that blew up in my face. If anyone can suggest a work-around or show me a sample script that will do this for me, I'd appreciate it.</p>
  
  <p>Example Column:</p>
  
  <pre>
  M1
  M1
  M1
  M21
  M21
  M23b
  M23b
  S2
  S23b
  S23B
  O1
  O2
  O2
  O2
  </pre>