私はこの機能を解決する方法について正しいアイデアを持っていると思いますが、私は確信していません なぜdocstringに表示された結果が得られないのですか?誰でもこの問題を解決するのを助けてくれますか?辞書の単語の頻度を返します
def list_to_dict(word_list):
'''(list of str) -> dict
Given a list of str (a list of English words) return a dictionary that keeps
track of word length and frequency of length. Each key is a word length and
the corresponding value is the number of words in the given list of that
length.
>>> d = list_to_dict(['This', 'is', 'some', 'text'])
>>> d == {2:1, 4:3}
True
>>> d = list_to_dict(['A', 'little', 'sentence', 'to', 'create', 'a',
'dictionary'])
>>> d == {1:2, 6:2, 8:1, 2:1, 10:1}
True
'''
d = {}
count = 0
for i in range(len(word_list)):
length = len(i)
if length not in d:
count = count + length
d[length] = {count}
count += 1
return d
'D [長さ] = {カウント}'間違いありませんあなたが欲しいもの。 –
なぜですか?長さがキーであり、頻度であるcountが値です。 – bigez
いいえ、長さがキーで、値は単一要素を含む* 'set' *です。これは周波数を表す' int'です。 –