python - how to find the sum of all of the numbers that correspond to certain words in a dictionary -



python - how to find the sum of all of the numbers that correspond to certain words in a dictionary -

so if have dictionary this:

a = ['a':1, 'b':2, 'c':3]

obviously sum of these 3 numbers six. how find sum in such list. mean like:

def compute_sum(a): total = 0 n in a: total += prices[n] homecoming total

so right that means can homecoming sum of list that? there other methods? how using same or different function?

you need alter loop slightly. assuming shopping_list shopping_list = {'bread':1.00, 'eggs':0.99} can this:

def compute_bill(shopping_list): total = 0.0 nutrient in shopping_list.keys(): total += shopping_list[food] homecoming total

python for-loop dictionary return function

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -