On Sun, Jun 12, 2005 at 04:55:38PM -0700, Xah Lee wrote:
> if i have
> mytext.replace(a,b)
> how to find out many many occurances has been replaced?

The count isn't returned by the replace method.  You'll have to count
and then replace.

def count_replace(a, b, c):
    count = a.count(b)
    return count, s.replace(b, c)

>>> count_replace("a car and a carriage", "car", "bat")
(2, 'a bat and a batriage')

Attachment: pgpAvDTGPd6LT.pgp
Description: PGP signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to