与えられた辞書では、各キーは単一の小文字で、各値はその文字で始まる小文字の数です。 strパラメーターは単一の小文字です。辞書の値に基づいて、その文字で始まる単語の割合を返します。Python辞書の文字の割合を取得
注:浮動小数点除算を使用してください。
def get_letter_percentage(dictionary, s):
'''(dict of {str : int}, str) -> float'''
# Start with a counter for the sum of the values.
count = 0
# And then look at the key and value of the dictionary
for (key, value) in dictionary.items():
これは私が立ち往生したところです。私は、浮動小数点除算を行うために値の合計を作成する必要があることを知っています。各値は、各文字のための単語の数である場合
# guessing it is something along these lines
count = len(values) #??
はこの宿題ですか? – jgritty