Project Censor Dispenser Delete Word Before and After Word


I new to Python, and computer programming in general, and have been trying to tackle this Censor Dispenser project. I’ve been stuck on step 5, where the objective is to create a function that will censor a specific word in 2 different lists, and the word before and after.
Here is what I have so far for this function, the error I’m getting is index is out of range.
I apoligize to the international community here for my code being newb-ish and out of wack.

Thanks for your help!

def censor_four(email, list_one, list_two):

email = email.split(" ")

for word in list_one:

    for word in list_two:

        for key_word in email:

             for i in (range(len(email))):

                if key_word[i] == word:

                    key_word[i] = "*"

                    key_word[i + 1] = "**"

                    key_word[i - 1] = "***"

email = " ".join(email)

return email
1 Like

4 for-loops!

Welcome to the forums!

I recommend at each juncture into your foray into the deep loop forest that you leave a trail of crumbs, so you can see what you’re trying to do.

for word in list_one:

#note, here, I wouldn't use the same keyword 'word' 
#for the inner loop, you can pick whatever 
#you want but I think using the same word 
#is going to confuse the issue
for word in list_one:
    for list_two_word in list_two:

for word in list_one:
    for list_two_word in list_two:
        for key_word in email: