在給定字典中,每個鍵都是單個小寫字母,每個值都是以該字母開頭的小寫字母的數量。 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 2012-03-27 15:31:13