Censor Dispenser Help Part 4

So I am not sure what is wrong with my code, whenever I insert email_three, it returns email_three with just the first and last term censored rather than having every word censored besides the first two.
Part Four: Write a function that can censor any occurance of a word from the “negative words” list after any “negative” word has occurred twice, as well as censoring everything from the list from the previous step as well and use it to censor email_three .

def censor3(email, negative):
  count = 0
  for word in negative:
    if (word in email) and (count <= 2):
      count += 1
      continue
    elif count > 2:
      email = email.replace(word, "XXXXXXX")
  return email

Note that when you call replace you are not specifying WHERE to replace, only what.

You may want to read exactly what different things do before you use them, otherwise you can’t meaningfully leverage their behaviour. str.replace simply doesn’t match what you’re looking to do, it’s useless for that, because it pays no attention to your conditions.

1 Like

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