敏感词文件内容:

敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights

 

代码:

def filtered_words(path='filtered_words.txt'):
    words = []
    with open(path, 'r', encoding='utf-8', newline='') as f:
        for line in f:
            words.append(line.strip())
    return words

def main():
    words = filtered_words()
    while True:
        #注意 python3中input相当于python2中raw_input
        text = input('content: ').strip()
        if text in words:
            print('Freedom')
        else:
            print('Human Rights')

 

相关文章:

  • 2022-12-23
  • 2021-12-06
  • 2021-12-29
  • 2022-01-14
  • 2021-05-15
  • 2022-12-23
  • 2021-06-15
  • 2021-12-03
猜你喜欢
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2021-11-02
  • 2022-12-23
相关资源
相似解决方案