Censor


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#

<In what way does your code behave incorrectly? Include ALL error messages.>
Your function fails on censor(“hey hey hey”,“hey”). It returns “hey hey hey” when it should return “*** *** ***”.

<What do you expect to happen instead?>
why doesn’t it change the word to ***

```python

def censor(text,word):
content=text.split()
for x in content:
if x==word:
x= “*” * len(x)
return " ".join(content)

<do not remove the three backticks above>

#2

x contains read only values from the list, any changes made to it, won’t persist given the loop will simply assign the next item/value from list to it in the following iteration of the loop


#3

so it’s better to assign with index of the list?
i’ll try that
thank you for your help~


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.