String replace with return value?

Roose moof at boof.moof
Mon Oct 11 05:47:48 EDT 2004


How can I do a "".replace operation which tells me if anything was 
actually replaced?

Right now I am doing something like:

if searchTerm in text:
	text = text.replace( searchTerm, 'other' )

But to me this seems inefficient since the 'in' operation will search 
through the whole string, and then the 'replace' will as well.

The strings are quite large, they're whole web pages.  Thanks for any help.

Roose



More information about the Python-list mailing list