首页 > 解决方案 > 在 Python 中计算推文中的脏话

问题描述

我想计算在我的推文数据库中出现了多少特定(脏话)词,下面是一个简单的例子。它没有给我想要的输出,因为在文本中引入“#”之后它变成了注释,但我不知道如何解决这个问题。

谢谢你。

text = RT @JGalt09: #Trump never owed millions $$$ to the Bank of China.  Another hoax from the #FakeNews media.    

word_list = ['fakenews', 'hoax']
swearword_count = 0

text_swear_count = text.lower().replace('.,#?!', ' ').split()

  for word in text_swear_count:
     if word in word_list:
         swearword_count += 1

标签: pythoncountword-list

解决方案


推荐阅读