【发布时间】:2019-03-11 12:51:05
【问题描述】:
我被要求编写一个程序,用"CENSORED" 替换数组test_tweets 中匹配banned_phrases 数组中的单词的单词。
test_tweets = [
"This politician sucks!",
"I hate this Government!",
"I can't believe we're living with such a bad politician. We were so foolish",
"Politicianname is a danger to society. I hate that he's so bad – it sucks."
]
banned_phrases = ["sucks", "bad", "hate", "foolish", "danger to society"]
我不知道是什么方法可以做到这一点。
【问题讨论】:
-
如何将“test_tweets”中匹配“banned_phrases”的单词替换为“CENSORED”?
-
您要过滤,然后替换吗?过滤意味着删除,这使得替换没有意义。
-
对不起,我的意思是替换