Python Show-Me-the-Code 第 0011 题 过滤敏感词
来源:互联网 发布:淘宝客买家入口 编辑:程序博客网 时间:2024/05/29 19:17
第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
北京程序员公务员领导牛比牛逼你娘你妈lovesexjiangge
思路:让用户输入词语,然后查找输入中是否含有敏感词,如果是则打印出 Freedom,否则打印出 Human Rights即可。为了方便交互,使用了Python的CMD模块。
0011.过滤敏感词.py
#!/usr/bin/env python#coding: utf-8import cmdimport sys# 存放敏感词文件的路径filtered_words_filepath = '/home/bill/Desktop/filtered_words.txt'class CLI(cmd.Cmd): def __init__(self): # 初始化,提取敏感词列表 cmd.Cmd.__init__(self) self.intro = 'Filtered Words Detective' self.words = map(lambda i: i.strip('\n'), open(filtered_words_filepath).readlines()) self.prompt = "> " # define command prompt def default(self, line): if any([i in line for i in self.words]): print 'Freedom' else: print 'Human Rights' def do_quit(self, arg): exit() return Trueif __name__ =="__main__": cli = CLI() cli.cmdloop()
0 0
- Python Show-Me-the-Code 第 0011 题 过滤敏感词
- Python Show-Me-the-Code 第 0012 题 替换敏感词
- python show-me-the-code 第0011题
- python show-me-the-code 第0004
- Python Show-Me-the-Code 第 0002 题 MySQL操作
- Python Show-Me-the-Code 第 0003 题 Redis操作
- Python Show-Me-the-Code 第 0004 题 统计单词
- Python Show-Me-the-Code 第 0021题 密码加密
- Python Show-Me-the-Code 第 0001题
- Python Show-Me-the-Code 第 0002题
- python show-me-the-code 第0010题
- python show-me-the-code 第0012题
- Python Show-Me-the-Code 第 0006 题 最重要的词
- Python Show-Me-the-Code 第 0000 题 图片右上角加数字
- Python Show-Me-the-Code 第 0001 题 生成激活码
- Python Show-Me-the-Code 第 0005 题 批量图片处理
- Python Show-Me-the-Code 第 0008 题 提取HTML正文内容
- Python Show-Me-the-Code 第 0009 题 提取网页中的超链接
- 使用模板引擎jade生成邮件HTML正文
- ViewHolder的经典用法<SparseArray>
- 马哥linux运维雄鹰社团第一届博客大赛
- Android中自定义Activity和Dialog的位置大小背景和透明度等
- 查看Activity任务栈的命令
- Python Show-Me-the-Code 第 0011 题 过滤敏感词
- 欢迎使用CSDN-markdown编辑器
- sqlite数据库,读写 sqlite3_exec
- 2015年我毕业了
- hadoop fs api
- android(4) 第一次启动滑动界面
- 单链表的简单操作
- Socket详解
- BZOJ3620【KMP】