title: How to get the length of an itertools.product?
body: <p>I am using <code>itertools</code> to run a numerical simulation iterating over all possible combinations of my input parameters. In the example below, I have two parameters and six possible combinations:</p>
  
  <pre><code>import itertools
  
  x = [0, 1]
  y = [100, 200, 300]
  
  myprod = itertools.product(x, y)
  
  for p in myprod:
      print p[0], p[1]
      # run myfunction using p[0] as the value of x and p[1] as the value of y
  </code></pre>
  
  <p>How can I get the size of <code>myprod</code> (six, in the example)? I'd need to print this before the <code>for</code> loop starts.</p>
  
  <p>I understand <code>myprod</code> is not a list. I can calculate <code>len(list(myprod))</code>, but this consumes the iterator so the <code>for</code> loop no longer works.</p>
  
  <p>I tried:</p>
  
  <pre><code>myprod2=copy.deepcopy(myprod)
  mylength = len(list(myprod2))
  </code></pre>
  
  <p>but this doesn't work, either. I could do:</p>
  
  <pre><code>myprod2=itertools.product(x,y)
  mylength = len(list(myprod2))
  </code></pre>
  
  <p>but it's hardly elegant and pythonic!</p>