title: How to log that an iterator yielded n or zero times?
body: <p>I want to log the number of things in an iterator (not trying to catch an empty iterator, like <a href="https://stackoverflow.com/q/60056208/2071807">this question</a>), after I've iterated over it and done something else for each thing.</p>
  
  <p>My instinct here is to use the <code>enumerate</code> built-in:</p>
  
  <pre class="lang-py prettyprint-override"><code>def foo_yielder():
       to_yield = ['foo', 'bar']
       for x in to_yield:
           yield x
  
  for i, x in enumerate(foo_yielder(), start=1):
      print(x)
  
  # Now log how many things we printed
  print(f"We logged {i} things")
  </code></pre>
  
  <p>But if the iterator has nothing to yield, <code>i</code> never gets defined.</p>
  
  <p>If this were Javascript I'd do:</p>
  
  <pre class="lang-js prettyprint-override"><code>`We logged ${i || 0} things`
  </code></pre>
  
  <p>Taking lessons from C, we could do:</p>
  
  <pre><code>i = 0
  for x in foo_yielder():
      print(x)
      i = i + 1
  print("We logged " + i + " things.")
  </code></pre>
  
  <p>But that seems incredibly lame somehow.</p>
  
  <p>Is there an elegant thing I could do here?</p>