title: Python: How to get the length of itertools _grouper
body: <p>I'm working with Python itertools and using groupby to sort a bunch of pairs by the last element. I've gotten it to sort and I can iterate through the groups just fine, but I would really love to be able to get the length of each group without having to iterate through each one, incrementing a counter.</p>
  
  <p>The project is cluster some data points. I'm working with pairs of (numpy.array, int) where the numpy array is a data point and the integer is a cluster label</p>
  
  <p>Here's my relevant code:</p>
  
  <pre><code>data = sorted(data, key=lambda (point, cluster):cluster)
  for cluster,clusterList in itertools.groupby(data, key=lambda (point, cluster):cluster):
      if len(clusterList) &lt; minLen:
  </code></pre>
  
  <p>On the last line: <code>if len(clusterList) &lt; minLen:</code>, I get an error that </p>
  
  <blockquote>
    <p>object of type 'itertools._grouper' has no len()</p>
  </blockquote>
  
  <p>I've looked up the operations available for <code>_groupers</code>, but can't find anything that seems to provide the length of a group.</p>