你可以这样得到你的分数:import re
sentence = list()
sentence.append(" hello my name is John")
sentence.append("good morning I am John")
sentence.append("hello I am Smith")
value = dict()
for sentenceC in sentence:
for word in sentenceC.strip().split(" "): # split with whitespace
try:
value[word.lower()] += 1
except KeyError:
value[word.lower()] = 1
print (value)
score = dict()
number = 1
for sentenceC in sentence:
for word in sentenceC.strip().split(" "): # split with whitespace
try:
score[number] += value[word.lower()]
except KeyError:
score[number] = value[word.lower()]
number += 1
print score
#output: {1: 7, 2: 8, 3: 7}