Python开发敏感词语过滤程序

开发敏感词语过滤程序,提示用户输入评论内容,如果用户输入的内容中包含特殊的字符:
敏感词列表 li = ["苍老师","东京热",”武藤兰”,”波多野结衣”]
则将用户输入的内容中的敏感词汇替换成***,并添加到一个列表中;如果用户输入的内容没有敏感词汇,则直接添加到上述的列表中。
content = input('请输入你的内容:')
li = ["苍老师","东京热","武藤兰","波多野结衣"]
i = 0
while i < 4:
    for li[i] in content:
        li1 = content.replace('苍老师','***')
        li2 = li1.replace('东京热','***')
        li3 = li2.replace('武藤兰','***')
        li4 = li3.replace('波多野结衣','***')
    else:
        pass
    i += 1

 

Golang版本

func main(){
	Words :=[]string{}
	SensibilityWords :=[]string{"苍老师","东京热","武藤兰","波多野结衣"}
	for {
		var comment  string
		fmt.Scanln(&comment)
		for _,str :=range SensibilityWords{
			fmt.Printf("str: %#v\n",str)
			if  strings.Contains(comment,str){
				comment = strings.Replace(comment, str, "*", -1)
			}
		}
		Words=append(Words,comment)

		fmt.Println(Words)
	}

}

  

posted @ 2018-03-22 22:59  运维面试辅导  阅读(4554)  评论(1)    收藏  举报