10. Censor


I've tried a lot of things and still can't make this work. The console says I can't assingn to function call. What does that mean? How can I make it work?

Here's the lesson:

Here's what the console says:
File "python", line 10
SyntaxError: can't assign to function call

Here's my code

text = raw_input("Input the sentence: ")
word = raw_input("Input the word you would like to censor: ")
censored = ""
def censor(text, word):
    text_splited = text.split(" ")
    censor = ["*" * len(word)]
    print text
    for words in range(len(text_splited)):
        if text_splited(words) == word:
            text_splited(words) = censor
censor(text, word)


This code:


looks like a function call. But text_splited is just a normal variable, why you want to pass parameters to it?


Isn't text_splited where the words from the text the user inputed are saved in? I'm trying to take the word that's equal to the one saved in 'word' and censor it


words is a numerical value, an index. If you want to retrieve element of text_splited at index words you have to use this code:



Ok, I managed to censor it, but I still can't return the whole text with the censored parts


You have to return elements of the text_splited separated by a single space and joined into the string... perfect use case for join method :slight_smile:

return ' '.join(text_splited)


I've been trying to do that but it the console says it was expecting a string or unicode but found a list. What am I doing wrong


Problem is in this line:

censor = ["*" * len(word)]

Print text_splited before return to get a better understanding of the problem.


Sorry, I still don't get it


Wait, I think I got it


Why the second element of the printed list (['**']) is... a list?


I got it, thank you for taking your to time to help me


You're very welcome :slight_smile:


Now an unrelated question: is this forum just Code Academy Python lessons related or is about Python in general?


This section is meant for the questions related to the exercises.

But please feel free to post everything that is not related to exercises in the corner bar section of this forum -> https://discuss.codecademy.com/c/Codecademy-Community-Lounge/Corner-Bar. You can even ask for help in your personal projects.


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