Help with---> https://www.codecademy.com/practice/projects/censor-dispenser

Hello,

I’m looking for some guidance. I’m currently trying to finish this project but i’m stuck on part 5.

" This final email has Mr. Cloudy in a frenzy. “We can’t let this information get out!” He tells you, “our company would be ruined! Censor it! Censor it all!”

Write a function that censors not only all of the words from the negative_words and proprietary_terms lists, but also censor any words in email_four that come before AND after a term from those two lists."

https://www.codecademy.com/practice/projects/censor-dispenser

so i got both lists of ‘negative_words’ and ‘proprietary_terms’ to come censored on the output but now i’m stuck on how to move forward on “but also censor any words in email_four that come before AND after a term from those two lists.”

def censor_it_all(proprietary_terms=proprietary_terms, negative_words=negative_words, email_four=email_four):
  index=0
  for word in proprietary_terms:
    if word in email_four: #and (word in proprietary_terms):
      email_four = email_four.replace(word, 'REDACTED')
      continue
  for word1 in negative_words:
    if word1 in email_four: #and (word in proprietary_terms):
      email_four = email_four.replace(word1, 'REDACTED')
  #return email_four
      print(email_four.find('REDACTED'))
      


print(censor_it_all())

I wanted to move forward using the .find function but don’t know how. I can’t imagine having to put in each term separately to find the index. I feel like I’m close but tell me if I’m not.

Thank You.

Hello!
I’ll give you some questions to think about (ordered in priority):

  1. Can you think of how to get the item in a list before a specific index? What about after?
  2. Now, what about an unknown index? What is that index is the last or first index of the list?
  3. How would you do this process for many indices? What about for a whole list?
  4. What tools (loops, built in methods, etc) would you use to complete these tasks?

I hope this helps!

which item are you referring to? The term in the email that is before and after the word that is to be censored?

Exactly!

Well I figured to get a more control over the words in the email I should .split() the words. I figured using .find() would be useful in finding each starting index of each word on the list but it won’t work with a list input.

1 Like