我在文本中搜索了以下3个句子,并使用sentence.append()
将它们附加到列表sentence
例如
sentence[0]=" hello my name is John"
sentence[1]="good morning I am John"
sentence[2]= "hello I am Smith"
我想根据每个单词在三个句子中出现的次数为每个句子和每个单词分配一个分数。在
例如:
^{pr2}$所以我用它来计算句子中每个单词的出现率(分数),我的问题是如何用它来计算句子的分数?
dict = {}
for sentenceC in sentence:
for word in re.split('\s', sentenceC): # split with whitespace
try:
dict[word] += 1
except KeyError:
dict[word] = 1
print (dict)
你可以这样得到你的分数:
将问题分解为子任务
然后组合任务以获得解决方案
^{pr2}$相关问题 更多 >
编程相关推荐