matching one time through a loop

Corey G. ctgaff at attbi.com
Thu May 30 04:54:59 EDT 2002


This comment made me realize just how little I know about Python.  Well,
it's only been 3 days now, but none the less.

By moving the regex out of the loop and only compiling it once, the
script is 3x faster than before and now out performs my original Perl
script.

Thanks for finding this.

-Corey


On Wed, May 29, 2002 at 10:34:30PM -0700, Sean 'Shaleh' Perry wrote:
> > 
> > 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.
> > 
> 
> if you do need the regex, there is only a need to compile it once before any of
> the loops rather than every time through.  The way it is now there is no point
> in compiling the regex as it is recomputed every time anyway.
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
---end quoted text---

-- 
Best Regards,
Corey





More information about the Python-list mailing list