A question I came up with:
I'm trying to write a function that replaces the first and the fourth letter of a word with the same letter just capitalized. Currently I am working with the string.replace() method. It works great for most of the time, except when there is an equal letter to the one on the fourth place before it. Example: "bananas" What I would expect the program to do is to return "BanAnas" but for a reason it return "BAnanas". If I use the word "submarine" it would just work fine, "SubMarine".
The code I wrote is this:
def old_macdonald(name):
name = name.replace(name[0], name[0].upper(), 1)
name = name.replace(name[3], name[3].upper(), 1)
return name
Can someone explain why this is happening?