早教吧作业答案频道 -->英语-->
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...的网友还看了以下:
如图是A、B、C三种固体物质的溶解度曲线.据图填空:(1)t1℃时,A的饱和溶液中溶质、溶剂、溶液 2020-05-15 …
下图是A、B两种固体物质的溶解度曲线,下列说法正确的是[]A.A物质的溶解度大于B物质的溶解度B. 2020-05-17 …
两光滑平行金属导轨(R=0)放在匀强磁场中且互垂直.一金属棒(R=0)沿导轨移动现用恒力拉它,经t 2020-05-22 …
关于周期函数的一个疑问设f(x)的最小正周期为T1g(x)的最小正周期为T2其中T1,T2属于实数 2020-06-04 …
一列简谐横波图象如图所示,t1时刻的波形如图中实线所示,t2时刻的波形如图中虚线所示,已知△t=t 2020-06-22 …
(2013•菏泽模拟)已知A、B两种固体物质的溶解度曲线图,请根据图示回答问题.(1)t1℃时,A 2020-06-30 …
(2014•浦东新区二模)在平直公路上行驶的a车和b车,其位移-时间图象分别为图中直线a和曲线b, 2020-07-03 …
python问题defgetquantities(orders):"""(dictof{str:l 2020-07-17 …
在一条笔直的公路上,有a、b、c三辆汽车,它们同时经过同一路标开始计时,此后的v-t图象如图所示, 2020-07-20 …
如图画的是两个由同一起点向同一方向作直线运动的物体的速度图象.()A.到t1时刻A停下B.到t2时刻 2020-12-09 …