# Imagine you are writing a program to help # a restaurant summarize the dishes sold yesterday. # A restaurant sells # soft vegetarian tacos, crunchy vegetarian tacos, # soft beef tacos, and crunchy beef tacos. # # Write a function called summarize_sale which takes # a list of strings representing the name of the dishes # customers have ordered, and returns a dictionary # containing the names of the dishes and # the number of times they are ordered. # # For example, if the incoming list is # ['soft vegetarian tacos', 'soft vegetarian tacos', # 'soft beef tacos', 'crunchy vegetarian tacos', # 'crunchy beef tacos', 'crunchy vegetarian tacos', # 'crunchy beef tacos', 'crunchy vegetarian tacos', # 'soft vegetarian tacos', 'soft beef tacos'] # Your function should return # {'soft vegetarian tacos': 3, # 'crunchy vegetarian tacos': 3, # 'soft beef tacos': 2, # 'crunchy beef tacos': 2} def summarize_sale(lst): sale_dict = {} for item in lst: if item in sale_dict.keys(): # sale_dict sale_dict[item] += 1 # increment the count else: sale_dict[item] = 1 # add (item, 1) return sale_dict sale_lst = ['soft vegetarian tacos', 'soft vegetarian tacos', 'soft beef tacos', 'crunchy vegetarian tacos', 'crunchy beef tacos', 'crunchy vegetarian tacos', 'crunchy beef tacos', 'crunchy vegetarian tacos', 'soft vegetarian tacos', 'soft beef tacos'] print(summarize_sale(sale_lst)) # write a function called report which takes a sale_dict and # displays the sale summary in a better, human-readable format. # For example: # Sale summary # soft vegetarian tacos --- 3 orders # crunchy vegetarian tacos --- 3 orders # soft beef tacos --- 2 orders # crunchy beef tacos --- 2 orders def report(dct): print("Sale summary") # for k,v in dct.items(): # print(k, "---", v, "orders") for k in dct: print(k, "---", dct[k], "orders") sale_dict = summarize_sale(sale_lst) report(sale_dict)