-4
我有以下3句,我在文字搜索,并将它们添加到使用sentence.append()
Python中每个单词的出现次数是一组字符串?
例如
sentence[0]=" hello my name is John"
sentence[1]="good morning I am John"
sentence[2]= "hello I am Smith"
我想要指定给每个句子的得分列表sentence
并根据每个字在所有3个句子中每个词的出现次数。
例如:
Hello score= 2 since it appeared twice **SOLVED**
sentence[0] score= hello score(which is 2) + my (1) + name (1) + is (1) + John(2) = 6
所以我使用了数句子中每个单词的出现(得分),我的问题是如何使用它来计算句子的成绩?
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)
所以......问题是什么? – jonrsharpe
对不起,这是不完整的,但我完成了它,我想知道如何使用字数来计算句子分数 –
我明白,“你好”的得分是2,但我不明白你是什么想为''语句[0]得分'“ –