I'm quite new to programming (and this is my first post to stackoverflow) however am finding this problem quite difficult. I am supposed to remove a given string in this case (WUB) and replace it with a space. For example:
A B C
song.replace("WUB", " ")
return " ".join(song.split())
WUB should be replaced by 1 space: 'AWUBBWUBC' should equal 'A B C'
str.replace() does not work "in-place"; it returns a new string that has had the requested replacement performed on it.
Return a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.
Do this instead:
def song_decoder(song): song = song.replace("WUB", " ") return " ".join(song.split())
In : song_decoder("BWUBWUBFF") Out: 'B FF'