Censor: take a look at my code


#1



start = str(raw_input("enter text: "))
strt = str(raw_input("enter the word: "))
def censor(text, word):
    n = "*" * len(word)
    a = text.split()
    print a
    for key in a:
        if key == word:
            key = n
    print a
    return " ".join(a)
    
print censor(start, strt)


#2

the for loop to replace words from text with asterisks is not working


#3

keyis your for loop iterator, its get assigned the values from the list. Any changes made to it will not persist.

create a list/string and append the words to this string/list, censor when needed, you decide if a list or a string is better


#4

Thank you! it worked :slight_smile:


#5