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)
the for loop to replace words from text with asterisks is not working
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
Thank you! it worked