早教吧作业答案频道 -->英语-->
python问题defgetquantities(orders):"""(dictof{str:listofstr})->dictof{str:int}Theordersdicthastablenamesaskeys('t1','t2',andsoon)andeachvalueisalistoffoodsorderedforthattable.Returnadictionarywhereeachkeyisaf
题目详情
python问题
def get_quantities(orders):
""" (dict of {str:list of str}) -> dict of {str:int}
The orders dict has table names as keys ('t1','t2',and so on) and each value
is a list of foods ordered for that table.
Return a dictionary where each key is a food from orders and each
value is the quantity of that food that was ordered.
>>> get_quantities({'t1':['Vegetarian stew','Poutine','Vegetarian stew'],'t3':['Steak pie','Poutine','Vegetarian stew'],'t4':['Steak pie','Steak pie']})
{'Vegetarian stew':3,'Poutine':2,'Steak pie':3}
"""
food_sums = {}
# Accumulate the food information here.
return food_sums
def get_quantities(orders):
""" (dict of {str:list of str}) -> dict of {str:int}
The orders dict has table names as keys ('t1','t2',and so on) and each value
is a list of foods ordered for that table.
Return a dictionary where each key is a food from orders and each
value is the quantity of that food that was ordered.
>>> get_quantities({'t1':['Vegetarian stew','Poutine','Vegetarian stew'],'t3':['Steak pie','Poutine','Vegetarian stew'],'t4':['Steak pie','Steak pie']})
{'Vegetarian stew':3,'Poutine':2,'Steak pie':3}
"""
food_sums = {}
# Accumulate the food information here.
return food_sums
▼优质解答
答案和解析
def get_quantities(orders):
""" (dict of {str: list of str}) -> dict of {str: int}
The orders dict has table names as keys ('t1', 't2', and so on) and each value
is a list of foods ordered for that table.
Return a dictionary where each key is a food from orders and each
value is the quantity of that food that was ordered.
>>> get_quantities({'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'], 't3': ['Steak pie', 'Poutine', 'Vegetarian stew'], 't4': ['Steak pie', 'Steak pie']})
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
"""
food_sums = {}
# Accumulate the food information here.
for tb, foods in orders.iteritems():
for food in foods:
food_sums[food] = food_sums.get(food, 0) + 1
return food_sums
""" (dict of {str: list of str}) -> dict of {str: int}
The orders dict has table names as keys ('t1', 't2', and so on) and each value
is a list of foods ordered for that table.
Return a dictionary where each key is a food from orders and each
value is the quantity of that food that was ordered.
>>> get_quantities({'t1': ['Vegetarian stew', 'Poutine', 'Vegetarian stew'], 't3': ['Steak pie', 'Poutine', 'Vegetarian stew'], 't4': ['Steak pie', 'Steak pie']})
{'Vegetarian stew': 3, 'Poutine': 2, 'Steak pie': 3}
"""
food_sums = {}
# Accumulate the food information here.
for tb, foods in orders.iteritems():
for food in foods:
food_sums[food] = food_sums.get(food, 0) + 1
return food_sums
看了 python问题defget...的网友还看了以下:
设有关系模式W(C,P,S,G,T,R),其中各属性含义是:C——课程,P——教师, s——学生,G 2020-05-23 …
设有关系模式W(C,P,S,G,T,R),其中各属性含义是;C——课程,P——教师,S——学生,G— 2020-05-24 …
设有关系模式W(C,P,S,G,T,R) ,其中各属性含义是:C——课程,P——教师,S——学生,G 2020-05-24 …
●设有关系模式W(C,P,S,G,T,R),其中各属性的含义是:C--课程,P--教师,S--学生, 2020-05-25 …
设有关系模式w(c,p,s,g,t,r),其中各属性的含义是:c课程,p教师,s学生,g成绩,t时间 2020-05-26 …
设有关系模式W(C,P,S,G,T,R),其中各属性的含义足:C—课程,P—教师,S—学生,G—成绩 2020-05-26 …
设有关系模式只(C,P,S,G,T,W),各属性含义为:C课程,P老师,S学生,G成绩,T时间,W教 2020-05-26 …
二、读读练练。爱惜时间的爱因斯坦爱因斯(sī)坦(tǎn)是伟大的科学家。他一生都十分珍惜时间。爱 2020-07-11 …
已知常数p>0,数列{an}满足an+1=|p-an|+2an+p,n∈N*.(1)若a1=-1, 2020-07-21 …
二、读读练练。爱惜时间的爱因斯坦爱因斯(sī)坦(tǎn)是伟大的科学家。他一生都十分珍惜时间。爱因 2020-11-02 …