title: Python - Count Elements in Iterator Without Consuming
body: <p>Given an iterator <code>it</code>, I would like a function <code>it_count</code> that returns the count of elements that iterator produces, without destroying the iterator.  For example:</p>
  
  <pre><code>ita = iter([1, 2, 3])
  print(it_count(ita))
  print(it_count(ita))
  </code></pre>
  
  <p>should print</p>
  
  <pre><code>3
  3
  </code></pre>
  
  <p>It has been pointed out that this may not be a well-defined question for <em>all</em> iterators, so I am not looking for a completely general solution, but it should function as anticipated on the example given.</p>
  
  <hr>
  
  <p>Okay, let me clarify further to my specific case.  Given the following code:</p>
  
  <pre><code>ita = iter([1, 2, 3])
  itb, itc = itertools.tee(ita)
  print(sum(1 for _ in itb))
  print(sum(1 for _ in itc))
  </code></pre>
  
  <p>...can we write the <code>it_count</code> function described above, so that it will function in this manner?  Even if the answer to the question is "That cannot be done," that's still a perfectly valid answer.  It doesn't make the question bad.  And the proof that it is impossible would be far from trivial...</p>