Deleting specific characters from a string

Fredrik Lundh fredrik at pythonware.com
Thu Jul 10 02:12:13 EDT 2003


Jeff Hinrichs wrote:

> I will post complete results tomorrow on the web but the short
> version is that using the .replace method is the overall champ by
> quite a bit.

umm.  on my box, testing with Python 2.1 and 2.3, a translate-based
function is 2-3 times faster even on very short strings with very few
replacement characters...

the more replacement characters you have, the bigger the difference.

(let me guess: you're including the maketrans call in the benchmark?
don't do that; it creates a constant table, which of course should be
put in a global variable.  or bound to a default argument, if you really
care about speed...)

</F>








More information about the Python-list mailing list