Why use regex finditer() rather than findall()
<p>What is the advantage of using <code>finditer()</code> if <code>findall()</code> is good enough?
<code>findall()</code> returns all of the matches while <code>finditer()</code> returns match object which can't be processed as directly as a static list.</p>

<p>For example:</p>

<pre><code>import re
CARRIS_REGEX = (r'&lt;th&gt;(\d+)&lt;/th&gt;&lt;th&gt;([\s\w\.\-]+)&lt;/th&gt;'
                r'&lt;th&gt;(\d+:\d+)&lt;/th&gt;&lt;th&gt;(\d+m)&lt;/th&gt;')
pattern = re.compile(CARRIS_REGEX, re.UNICODE)
mailbody = open("test.txt").read()
for match in pattern.finditer(mailbody):
    print(match)
print()
for match in pattern.findall(mailbody):
    print(match)
</code></pre>

<p>Output:</p>

<pre class="lang-none prettyprint-override"><code>&lt;_sre.SRE_Match object at 0x00A63758&gt;
&lt;_sre.SRE_Match object at 0x00A63F98&gt;
&lt;_sre.SRE_Match object at 0x00A63758&gt;
&lt;_sre.SRE_Match object at 0x00A63F98&gt;
&lt;_sre.SRE_Match object at 0x00A63758&gt;
&lt;_sre.SRE_Match object at 0x00A63F98&gt;
&lt;_sre.SRE_Match object at 0x00A63758&gt;
&lt;_sre.SRE_Match object at 0x00A63F98&gt;

('790', 'PR. REAL', '21:06', '04m')
('758', 'PORTAS BENFICA', '21:10', '09m')
('790', 'PR. REAL', '21:14', '13m')
('758', 'PORTAS BENFICA', '21:21', '19m')
('790', 'PR. REAL', '21:29', '28m')
('758', 'PORTAS BENFICA', '21:38', '36m')
('758', 'SETE RIOS', '21:49', '47m')
('758', 'SETE RIOS', '22:09', '68m')
</code></pre>

<p>I ask this out of curiosity.</p>

<p>Sometimes it's superfluous to retrieve all matches. If the number of matches is really high you could risk filling up your memory loading them all.</p>

<p>Using iterators or generators is an important concept in modern python. That being said, if you have a small text (e.g this web page) the optimization is minuscule.</p>

<p>Here is a related question about iterators: <a href="http://stackoverflow.com/questions/628903/performance-advantages-to-iterators">Performance Advantages to Iterators?</a></p>

python regex match string-matching iterable