for i in text:
if i==" ":
for j in word:
If you are trying to post code please post it correctly. Use the codify button the one that looks like
Here is some code for you to examine, I made it human readable so you should be able to figure it out. Take my code and rewrite it so that you gain understanding of what it is doing.
def censor(text, censor): """ This function takes a string, converts it to a list with the string function split() After it splits the string it searches for a match to the censor word, it then replaces the word with a string of '*' the correct length. :param text: Required as a string :param censor: Requires a one word string :return: Returns modified string """ new_text = text.split(' ') for word_number, word in enumerate(new_text): if censor == word: new_text[word_number] = '*' * len(word) return ' '.join(new_text)
10/15 - what is wrong here?
you can use the built in replace method to solve this problem too
def censor(text, word): return text.replace(word, "*"*len(word)) print(censor("this hack is wack hack", "hack"))
or you can go by this
def censor(text, word): return ("*"*len(word)).join(text.split(word)) print(censor("this hack is wack hack", "hack"))