Deleting specific characters from a string

Fredrik Lundh fredrik at pythonware.com
Thu Jul 10 19:18:43 CEST 2003


Michael Chermside wrote:

> RE's are NOT renown for their speed when doing simple character
> replacement, deletion or insertion on strings. But _I_ haven't timed
> it either, so I'm going to shut up now.

I rewrote the re.sub implementation for 2.2, making it about 10 times
faster for cases like this (compared to the 2.1 version).

if you precompile the regexp, p.sub(text, "") is nearly as fast as the
translate method under 2.3.  ymmv.

</F>








More information about the Python-list mailing list