一、需求

1、 有一个文件,里面有一些敏感词汇,用户输入一段话,若包含这些词,就用**代替,并输出

 

二、实现代码

f = open('lib.txt', 'r')
result = ''
f1 = input('请输入一段话: ')
for line in f: #遍历每一个敏感词
    if line.strip() in f1: #判断是否包含敏感词
        result = f1.replace(line.strip(), '**')
        f1 = result
f.close()
print(result)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-06-11
  • 2021-12-05
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2021-12-14
  • 2022-12-23
  • 2021-08-15
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案