20170513 Python Workbook 0011 filter Sensitive words

Source: Internet
Author: User

#!/usr/bin/env python
#-*-coding:utf-8-*-

# No. 0011: Sensitive word text file Filtered_words.txt, the contents of the following content,
# When the user enters a sensitive word, print out the Freedom, otherwise print out the Human rights.
Import re


def filted_word (filename):
Word_list=[] #定义一个空列表
with open (filename, ' r ') as F: #以读打开文件
For line in F: #以行为单位遍历文件
Content = Re.sub (r ",", line) #替换掉空格符
Word_list.append (Content.strip ()) #以行为单位添加进列表
Print (word_list)
return word_list
def filer (input_word,f_file):
If Input_word in Filted_word (f_file): #判断输入是否在列表中
Print (' Freedom ')
Else
Print (' Human right ')
Add = ' F:\python\Python workbook \sensitivewords.txt '
Name = input (' Please enter word: ') #输入word
If __name__== ' __main__ ':
Filer (Name,add)

20170513 Python Workbook 0011 filter Sensitive words

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.