白衣染霜花
参考代码#!/usr/bin/env python# -*- coding: utf-8 -*-#python 2.7import reprint u'请输入英语句子:'wz = raw_input()#整句转换为小写s = wz.lower()#小写单词的正则表达式r='[a-z]+'#找到所有单词ws = re.findall(r,s)#定义一个字典来存储单词和次数dt = {}for w in ws: dt[w] = dt.setdefault(w,0)+1print u'输入查找的英语单词:'#输入需要查找的单词,转换成小写fw = raw_input().lower() if(dt[fw]>3): print u'该单词出现次数超过3次,现在整句转换为小写。输出:' print selse: print u'该单词出现次数小于等于3次,整句删除该单词。输出' #re.I忽略大小写匹配 print re.compile(fw,re.I).sub("",wz)运行测试c:\pyws>python wenzhang.py请输入英语句子:I LOVE THE APPLE, THE big APPle, The red Apple输入查找的英语单词:the该单词出现次数小于等于3次,整句删除该单词。输出I LOVE APPLE, big APPle, red Apple c:\pyws>python wenzhang.py请输入英语句子:I LOVE THE APPLE, THE big APPle, The red Apple, The delicious Apple输入查找的英语单词:the该单词出现次数超过3次,现在整句转换为小写。输出:i love the apple, the big apple, the red apple, the delicious apple