python show-me-the-code 第0011题
来源:互联网 发布:天顶星人 知乎 编辑:程序博客网 时间:2024/05/22 00:11
第 0011 题: 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。
北京程序员公务员领导牛比牛逼你娘你妈lovesexjiangge
分析:判断输入的词中是否含有敏感词
预备工作:创建一个文档filtered_words.txt,并且把上述敏感词保存在文档中,文档格式设置为utf-8。代码如下:
# -*- coding: utf-8 -*-def check(input,filtered_words):for i in filtered_words:if i in input: #若文档中的词出现在输入的词中return 'Freedom'return 'Human Rights'if __name__=='__main__':file = open('filtered_words.txt')filtered_words=[line.replace('\n','') for line in file] #去除换行符print check('北京欢迎你',filtered_words)print check('hello world!',filtered_words)
结果如下:
FreedomHuman Rights
0 0
- 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 第 0011 题 过滤敏感词
- Python Show-Me-the-Code 第 0000 题 图片右上角加数字
- Python Show-Me-the-Code 第 0001 题 生成激活码
- Python Show-Me-the-Code 第 0005 题 批量图片处理
- Python Show-Me-the-Code 第 0006 题 最重要的词
- Python Show-Me-the-Code 第 0008 题 提取HTML正文内容
- Python Show-Me-the-Code 第 0009 题 提取网页中的超链接
- Python Show-Me-the-Code 第 0010 题 生成验证码图片
- 常用的 redis操作
- 关于我及各种链接
- python中主线程等待子线程完成的实现(join())
- BroadcastReceiver 广播在应用内部注册
- Ubuntu 命令行 安装 Java
- python show-me-the-code 第0011题
- 使用Eclipse时一些报错
- 友盟与听云比较
- 事实上,最糟的并不是李世石完败AlphaGo......
- HDU 5521 15年亚洲赛现场题目 图论之最短路
- 【面试】数据结构
- hdu3339 In Action(floyd+背包)
- BZOJ1877晨跑
- 学习Jave的第一步:JDK的安装和变量配置