Feb-11-2020, 04:33 PM
str_to_clean = "This is an example of a paragraph that I have. I would like to remove any sentences containing certain words, for example the word bad, or naughty. If it has bad, I don't want it. If it is naughty, I do not want it. If it doesn't, I want to keep it." cleaned_str = "" for sentence in str_to_clean.split("."): if not (re.search("bad|naughty", sentence, flags=re.IGNORECASE)): cleaned_str = cleaned_str + sentence print(cleaned_str)The above works, but it seems...not the best.