matching one time through a loop

Terry Reedy tjreedy at udel.edu
Wed May 29 21:59:29 EDT 2002


"Corey G." <ctgaff at attbi.com> wrote in message
news:mailman.1022721348.30810.python-list at python.org...
> I have a script that parses some email from a Maildir directory
> and I am looking for the number 550.  I want to stop searching once
> the first occurrence is found in order to save time and be
efficient.
> This sort of thing can be done in Perl using the "last" statement.
> I achieved my goal by using a counter but it seems terribly
inefficient.
> Any ideas?

If you want to stop at first, then there is no need to count.  Just
stop.  Also, searching for literal string should be more efficient
with string.find than more general re stuff.

TJR






More information about the Python-list mailing list