I am making a "Wordle" type of game in Python and wanted to remove the last letters you wrote when you press backspace and it worked in most cases but I have a problem if your word has the letter that are the same for example "start".
I tried using the .replace()
function like this:
word = 'start'
new_word = word.replace(word[4], '', 1)
print(new_word)
But the result isn't 'star'
, but rather 'sart'
.
As you see it replaces the first 't' and not the last.
Does anyone know how to replace the last 't'
but the solution needs to work on any case, like in 'aaaaa'
it just needs to replace the last 'a'
?