str.replace()
allows to replace a substring in a string with something else.
I have the problem of repeated whitespaces after the replacement:
>>> 'word word to be removed word'.replace('to be removed', '')
'word word word'
Note the two whitespaces after the second word
.
Is there a way to replace a substring with a backspace that would remove one space? (I know that the string will be made of words separated by spaces)