title: Using Groupby to Group a Column in an Access Table in Python
body: <p>I have been playing with the groupby function from the itertools module for a while now (like days) </p>
  
  <pre><code>for k, g in groupby(data, keyfunc):
  </code></pre>
  
  <p>I am really having trouble understanding the syntax. I've tried a variety of different things, but I really don't know what to put in for "data" and "keyfunc" and get it to return the groups of data I want in a print statement.</p>
  
  <p>What am I doing is looping through rows in an access table. </p>
  
  <p>I set a variable to a cursor search (which is sorted) in the access table and pull out the column I want.</p>
  
  <pre><code>for row in cursor:
      print row.ROAD_TYPE
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>TRUNK ROAD
  TRUNK ROAD
  TRUNK ROAD
  TRUNK ROAD
  COLLECTOR HIGHWAY
  COLLECTOR HIGHWAY
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  MAJOR ROAD
  MAJOR HIGHWAY
  </code></pre>
  
  <p>I want to group these values together and have it return the string value for me so it prints something like this:</p>
  
  <pre><code>TRUNK ROAD
  TRUNK ROAD
  TRUNK ROAD
  TRUNK ROAD
  
  COLLECTOR HIGHWAY
  COLLECTOR HIGHWAY
  
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  ACCESS ROAD
  
  MAJOR ROAD
  
  MAJOR HIGHWAY
  </code></pre>
  
  <p>Finally, I want to group a second column based on these new groups so that I get something like this:</p>
  
  <pre><code>TRUNK ROAD  M1
  TRUNK ROAD  M1
  
  TRUNK ROAD  M2
  
  TRUNK ROAD  M3
  
  
  COLLECTOR HIGHWAY  M1
  
  COLLECTOR HIGHWAY  M2
  
  
  ACCESS ROAD  M1
  ACCESS ROAD  M1
  
  ACCESS ROAD  M3
  ACCESS ROAD  M3
  
  ACCESS ROAD  M7
  ACCESS ROAD  M7
  
  ACCESS ROAD  M8
  
  
  MAJOR ROAD  M8
  
  
  MAJOR HIGHWAY  M8
  </code></pre>
  
  <p>I know this is probably way less difficult than I've made it out for myself, I feel there's a simple answer, but I'm completely stumped and I can't seem to find an example on the internet that explains the groupby syntax in a way that I understand. Please feel f</p>