Censor


#1



Hi, Guys. Whats wrong with my code:

def censor(text,word):
    text = text.split()
    for word in text:
        if word in text:
            word == '*' * len(word)
    return " ".join(text)

I get:

Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".


#3

Please explain yourself when espousing a superlative. Thank you.

Why is the default .split() not acceptable?


#5

First, change name of your for variable name. By choosing word you are overriding param name, so you can't use it in for loop. Change it's name to censored or something else.
Second, you are using compare operator == instead of assigning =.

Variable used in this for loop can be used to read value, but I think it can't be used to change it's value. You should change list items directly in list.

You can use this loop to find index of word:

for index, word in enumerate(text):

Check if word == censored, if True then you can use index variable to change list item value

    text[index] = '*' * len(word)

Also, check if your function is case-insensitive.


Censor