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')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFCrOQSJd01MZaTXX0RAm27AJ47sF1yYVKYIboeSsIcAV QZuhaGPgCfRqRH
mdJtjbwypq/h7XcmVpZOfhs=
=9m3p
-----END PGP SIGNATURE-----