Codecademy Forums

Censor Dispenser

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

Hello there,
Can anyone help me? I am on the last part of Censor Dispenser: https://www.codecademy.com/practice/projects/censor-dispenser
question 3, where there are a list of words in a list that need to be censored in a block of string text. I’ve scoured the forums and the internet for a solution but can’t find any way to do this in a way that works. Below is my code so far:

def censor_list (cen_lst, text): 
	new_text = []
	text_list = text.split(" ")
	for i in cen_lst:
		for n in text_list:
			if i == n:
				n = '*'*len(n)
				new_text.append(n)
			else: 
				n = n
				new_text.append(n)
	return " ".join(new_text)      
      


proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithm", "her", "herself"]

print(censor_list(proprietary_terms, email_two))

Any help would be greatly appreciated.

xxx

Solution to what though? The whole exercise? Maybe try to split it up into steps and implement one step at a time. A good place to start is to consider how you would carry it out manually.
An example of a smaller part of the problem that you can solve is to censor just one word using only one proprietary word. If you put that in a funciton then you could make another function that does the same but for multiple words by using the function you made before. And then after that a function that can do it for multiple input words.

1 Like

Thanks for your help. I managed to do it, by working back from the solution.