I have a sentence as follows:
s="This is my cat who is my ally and this is my dog who has started to finally act like one."
I want to replace certain words in the sentence with other words. Example:
cat with bat, ally with protector.
Now the problem occurs with similar words. For example ally and finally
s="This is my cat who is my ally and this is my dog who has started to finally act like one."
for r in (("cat", "bat"),("ally", "protector")):
s = s.replace(*r)
print(s)
This should give me:
This is my bat who is my protector and this is my dog who has started to finally act like one.
But it gives me the following output affecting finally because of ally:
This is my bat who is my protector and this is my dog who has started to finprotector act like one.
It affects finally and converts it to finprotector
. I don't want this. How can I solve this issue? Any help will be appreciated.