私は文字列、辞書を次の形式で持っています:
('the head', {'exploded': (3.5, 1.0), 'the': (5.0, 1.0),
"puppy's": (9.0, 1.0), 'head': (6.0, 1.0)})
各括弧は、(スコア、標準偏差)に対応するタプルです。各タプルの最初の整数の平均をとっています。私はこれを試しました:
def score(string, d):
for word in d:
(score, std) = d[word]
d[word]=float(score),float(std)
if word in string:
word = string.lower()
number = len(string)
return sum([v[0] for v in d.values()]) / float(len(d))
if len(string) == 0:
return 0
私が走るとき:
print score('the head', {'exploded': (3.5, 1.0), 'the': (5.0, 1.0),
"puppy's": (9.0, 1.0), 'head': (6.0, 1.0)})
取得する必要があります5.5
が、代わりに取得してい5.875
ます。関数の何が正しい答えを得ることができないのか理解できません。