Embed presentation
Downloaded 14 times
























![def censor(text, word):
list1 = text.split()
newlist = []
final_list = []
for w in list1:
if w == word:
newlist.append("*" * len(word))
else:
newlist.append(w)
final_list = " ".join(newlist)
return final_list](https://image.slidesharecdn.com/pythonprogramminglab16-150310220559-conversion-gate01/75/Python-programming-lab16-25-2048.jpg)






















This Python code defines a function called censor that takes in a text string and a word to censor. It splits the text into a list of words, censors any instances of the given word by replacing it with asterisks of the same length, joins the words back into a string with spaces, and returns the censored text.
























![def censor(text, word):
list1 = text.split()
newlist = []
final_list = []
for w in list1:
if w == word:
newlist.append("*" * len(word))
else:
newlist.append(w)
final_list = " ".join(newlist)
return final_list](https://image.slidesharecdn.com/pythonprogramminglab16-150310220559-conversion-gate01/75/Python-programming-lab16-25-2048.jpg)





















