I know you're able to link the .replace() method to make multiple substring replacements.
But there's a problem when I do this:
phrase = "AppleBananaCarrot"
print(phrase.replace("Banana","Apple").replace("Apple","Banana"))
Here, I wanted Banana and Apple to swap, so that it printed: BananaAppleCarrot
Instead it printed: BananaBananaCarrot
In other words: I don't want a replacement substring to be replaced again. The only way I see this being solved is if there was a way to use the .replace() method simultaneously instead of subsequently. Does anyone know how to do that or something similar?
I tried looking on stackoverflow, but the questions were just asking how to do it subsequently more efficiently. I want to do it simultaneously. I couldn't find a question for that.