title: In python, how to 'if finditer(...) has no matches'?
body: <p>I would like to do something when finditer() does not find anything.</p>
  
  <pre><code>import re
  pattern = "1"
  string = "abc"  
  matched_iter = re.finditer(pattern, string)
  # &lt;if matched_iter is empty (no matched found&gt;.
  #   do something.
  # else
      for m in matched_iter:
          print m.group()
  </code></pre>
  
  <p>The best thing I could come up with is to keep track of found manually:</p>
  
  <pre><code>mi_no_find = re.finditer(r'\w+',"$$%%%%")   # not matching.
  found = False
  for m in mi_no_find:
      print m.group()
      found = True
  if not found:
      print "Nothing found"
  </code></pre>
  
  <p>Related posts that don't answer:  </p>
  
  <ul>
  <li>Counting finditer matches: <a href="https://stackoverflow.com/questions/3895646/number-of-regex-matches">Number of regex matches</a> (I don't need to count, I just need to know if there are no matches).</li>
  <li>finditer vs match: <a href="https://stackoverflow.com/questions/4646904/different-behavior-when-using-re-finditer-and-re-match">different behavior when using re.finditer and re.match</a> (says always have to loop over an iterator returned by finditer)</li>
  </ul>
  
  <p>[edit]<br>
  - I have no interest in enumerating or counting total output. Only if found else not found actions.<br>
  - I understand I can put finditer into a list, but this would be inefficient for large strings. One objective is to have low memory utilization.</p>