Hi guys i have tried to strip special characters in my code but it is not working, i have done everything i can but words before special characters refuse to censor e.g ( help! ) i added help in the negative_words but the code does not even identify that help! exist in negative_word since i have applied strip, i expected it to identify it. That means my strip does not work
Also i noticed that learning algorithms was not censored and i found out that this is from the email content being split which ends up splitting the learning algorithms as two words instead of one. Is there any other way to iterate through a string without splitting it and converting it to a list?
def censor_fours (email_content, negative_word_list, censor_list): email_list_content =  email_content_lower = email_content.lower() content = email_content_lower.split() negative_word_new =  censor_new =  special_char = [",", "!", ".", "/", "("] for lower_word in range(len(negative_word_list)): for i in special_char: negative_word_new.append(negative_word_list[lower_word].lower().strip(i)) for censor in range(len(censor_list)): for i in special_char: censor_new.append(censor_list[censor].lower().strip(i)) for word_len in range(len(content)): #print(content[word_len]) similar =  before = "" after = "" for i in special_char: clean_word = content[word_len].strip(i) if clean_word in negative_word_new or clean_word in censor_new: print(clean_word) word_before = content[word_len - 1] word_after = content[word_len + 1] similar.append(clean_word) for word in similar: censored_word = "" for letter in range(len(word)): censored_word += "x" content[word_len] = content[word_len].replace(word, censored_word) for letter in range(len(word_before)): before += "y" for letter in range(len(word_after)): after += "z" content[word_len-1] = content[word_len - 1].replace(word_before, before) content[word_len+1] = content[word_len+1].replace(word_after, after) #print(email_list_content) return " ".join(content) call_censor_fours = censor_fours(email_four, negative_words, proprietary_terms) print(call_censor_fours)