过滤一遍并将敏感词替换之后剩余字符串中新组成了敏感词语,这种情况就要用递归来解决,直到过滤替换之后的结果和过滤之前一样时才算结束
第一步:建立一个敏感词库(.txt文本)
第二步:编写代码在文章中过滤敏感词(递归实现)
# -*- coding: utf-8 -*-
# author 代序春秋
import os
import chardet
# 获取文件目录和绝对路径
curr_dir = os.path.dirname(os.path.abspath(__file__))
# os.path.join()拼接路径
sensitive_word_stock_path = os.path.join(curr_dir, 'sensitive_word_stock.txt')
# 获取存放敏感字库的路径
# print(sensitive_w