python删除输入句子中含有txt文件里的词汇
text=raw_input("Enterthemoivereview:")words=text.split()word_dict={}forwinwords:ifwno...
text = raw_input("Enter the moive review:")
words = text.split()
word_dict = {}
for w in words:
if w not in word_dict:
word_dict[w] = 1
else:
word_dict[w] = word_dict[w] + 1
print word_dict
这是原先的程序 另外还有两个分别是含有高频名词和高频动词的txt 想在count word之前先读取两个txt里面的词汇 把句子中与txt里重叠的词汇都删除 只count形容词 求求大家帮帮我!谢谢! 展开
words = text.split()
word_dict = {}
for w in words:
if w not in word_dict:
word_dict[w] = 1
else:
word_dict[w] = word_dict[w] + 1
print word_dict
这是原先的程序 另外还有两个分别是含有高频名词和高频动词的txt 想在count word之前先读取两个txt里面的词汇 把句子中与txt里重叠的词汇都删除 只count形容词 求求大家帮帮我!谢谢! 展开
2个回答
展开全部
# -*- coding: cp936 -*-
text = raw_input("Enter the moive review:")
words = text.split()
verbfile=open(r"~/verb.txt") #用你自己的文件名路径替换
adjfile=open(r"~/adj.txt") #用你自己的文件路径替换
word_dict=verbfile.read().split()+adjfile.read().split()
verbfile.close()
adjfile.close()
wordscopy=[]
wordscopy[:]=words
for word in words:
if word in word_dict:
wordscopy.remove(word)
print wordscopy
print "count:%d"%len(wordscopy)
text = raw_input("Enter the moive review:")
words = text.split()
verbfile=open(r"~/verb.txt") #用你自己的文件名路径替换
adjfile=open(r"~/adj.txt") #用你自己的文件路径替换
word_dict=verbfile.read().split()+adjfile.read().split()
verbfile.close()
adjfile.close()
wordscopy=[]
wordscopy[:]=words
for word in words:
if word in word_dict:
wordscopy.remove(word)
print wordscopy
print "count:%d"%len(wordscopy)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询