Problem 2: Fill in the function shopSmart(orders,shops) in shopSmart.py, which takes an orderList (like the kind passed in to FruitShop.getPriceOfOrder) and a list of FruitShop and returns the FruitShop where your order costs the least amount in total. Don't change the file name or variable names, please. Note that we will provide the shop.py implementation as a "support" file, so you don't need to submit yours. Test Case: We will check that, with the following variable definitions: orders1 = [('apples',1.0), ('oranges',3.0)] orders2 = [('apples',3.0)] dir1 = {'apples': 2.0, 'oranges':1.0} shop1 = shop.FruitShop('shop1',dir1) dir2 = {'apples': 1.0, 'oranges': 5.0} shop2 = shop.FruitShop('shop2',dir2) shops = [shop1, shop2] The following are true: shopSmart.shopSmart(orders1, shops).getName() == 'shop1' and shopSmart.shopSmart(orders2, shops).getName() == 'shop2'
def shopSmart(orders,shops):
dic = {}
for i, j in enumerate(orders):
dic[j] = shops[i]
return min(dic)
Comments
Leave a comment