x

Overall, this solution works!
However, it is going to be slow. If you put the following after line 57:
print(new_string)
You will see the number of same operations got push onto the stack.
Look up "memoization"