So I nearly have this one working, here's my code so far:
def censor(text, word): word_list = text.split() ast = "*" * len(word) new_text = "" for w in word_list: if w != word: new_text = new_text + w elif w == word: new_text = new_text + ast return new_text
Problem is that it doesn't add in the spaces between words. I tried to add a " " to the beginning/middle/end of the statements on line 7 and 9, but becuase it doesn't know whether a word is first or last or inbetween and therefore if it needs a spcae in front or after it or both, it will always be wrong at some point - is it possible to do it using this approach, or should I be going about this in a different way?
Any help appreciated