github/Show me the code (11)

第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge

# -*- coding: utf-8 -*-
import re

def read_words(filename="filtered_words.txt"):
    words = []
    with open(filename, 'r') as f:
        lines = f.readlines()
        for l in lines:
            words.append(l)
    return words
    
def filter_words():
    input = raw_input("Input: ")
    words = read_words()
    for i in range(len(words)):
        if re.match(input, words[i]):
            print "Freedom"
            return
    print "Human Rights"
    return

filter_words()

你可能感兴趣的:(github/Show me the code (11))