The problem is that .replace(old, new)
returns a copy of the string in which the occurrences of old
have been replaced with new
.
Instead, you can swap the character at index i
using:
new_str = old_str[:i] + "b" + old_str[i+1:]
The problem is that .replace(old, new)
returns a copy of the string in which the occurrences of old
have been replaced with new
.
Instead, you can swap the character at index i
using:
new_str = old_str[:i] + "b" + old_str[i+1:]