Censor


#1

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

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/censor-?action=lesson_resume

<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 “*** *** ***”. I thought this would work but it turns out didnt.

<What do you expect to happen instead?>
id’d like to know what i didi wrong and how could i change it

```python

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

<do not remove the three backticks above>

#2

item contains read-only values from the list, any changes made to it won’t persist given the loop will assign the next value in list to loop iterator (item) in the following iterations

you will need to find a way to make the change persist outside the loop


#3

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