python的其中一个强大之处就是它可以方便的集成很多的非标准库,今天在GitHub上溜达又发现了一个脏话处理神器,导入better_profanity库后,只需要几行代码就能搞定了,相当nice!
使用pip的方式将better_profanity非标准库安装好,这个库好像在清华大学的镜像站中没有,其他镜像站不知道有没有,于是下载时没有使用镜像站,默认到官方去下载即可。
pip install better_profanity
from better_profanity import profanity
默认情况下就只能处理英文的脏话。
censored_text = profanity.censor("you are bitch")
print(censored_text)
可以看到其中bitch字符被认为是脏话已经处理成****字符了。