python - 在 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
解决方案
推荐阅读
- android - 如何为典型的手机屏幕 480x800 hdpi 创建布局?
- javascript - 外部css在reactjs中自动转换为内部css,因此无法应用多个css文件
- android - PyQt5 GUI for android vs Kivy GUI
- html - 使用 CSS 类继承引导网格系统
- javascript - Javascript:检查网址是否有效并以“http//”或“https://”开头
- c# - 过滤某些单词的 HTML 文件的最佳方法
- r - “dplyr”不知道分开
- angular - 如何在 Angular 中添加烤面包机?
- jquery - 如何使用 jquery 在 Angular 7 中使用引导弹出框?
- python - 如何减少 xarray 中重复行的数量?