def shopSmart2(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ priceList = [shop.getPriceOfOrder(orderList) for shop in fruitShops] # a list with al the total prices of shops in fruitShops return [shop for shop in fruitShops if shop.getPriceOfOrder(orderList) == min(priceList)][0] # a list of all the shops with the lowest price and return the first
def shopSmart(orderList, fruitShops): menor = fruitShops[0].getPriceOfOrder(orderList) tienda = fruitShops[0] for shop in fruitShops: if shop.getPriceOfOrder(orderList) < menor: menor = shop.getPriceOfOrder(orderList) tienda = shop else: None return tienda
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ num = fruitShops[0].getPriceOfOrder(orderList) name = fruitShops[0] for shop in fruitShops: if shop.getPriceOfOrder(orderList) <= num: num = shop.getPriceOfOrder(orderList) name = shop return name
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ output = fruitShops[0] min = output.getPriceOfOrder(orderList) for shop in fruitShops[1:]: if shop.getPriceOfOrder(orderList) < min: output = shop min = shop.getPriceOfOrder(orderList) return output
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" cost = 1000.0 for shop in fruitShops: if cost > shop.getPriceOfOrder(orderList): cost = shop.getPriceOfOrder(orderList) cheapest = shop return cheapest
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ Best = fruitShops[0] Lowest = fruitShops[0].getPriceOfOrder(orderList) for shop in fruitShops: if shop.getPriceOfOrder(orderList) < Lowest: Best = shop Lowest = shop.getPriceOfOrder(orderList) return Best
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ best_price = fruitShops[0].getPriceOfOrder(orderList) best_shop = fruitShops[0] for shop in fruitShops: if shop.getPriceOfOrder(orderList) < best_price: best_price = shop.getPriceOfOrder(orderList) best_shop = shop return best_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" shopPrice = 100000000 #Does python have an Infinite KEYWORD??? for shop in fruitShops: if shopPrice > shop.getPriceOfOrder(orderList): bestShop = shop shopPrice = shop.getPriceOfOrder(orderList) return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ minCost = 100000000000000; minShop = None; for shop in fruitShops: if shop.getPriceOfOrder(orderList) < minCost: minShop = shop minCost = shop.getPriceOfOrder(orderList) return minShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" chosen_shop = fruitShops[0] #set the first shop as default cost = fruitShops[0].getPriceOfOrder(orderList) for shop in fruitShops: if shop.getPriceOfOrder(orderList) < cost: chosen_shop = shop cost = shop.getPriceOfOrder(orderList) return chosen_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" cost = fruitShops[0].getPriceOfOrder for shop in fruitShops: if shop.getPriceOfOrder(orderList) < cost : cost = shop.getPriceOfOrder(orderList) optimalShop = shop return optimalShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" minCost = None minShop = None for shop in fruitShops: if shop.getPriceOfOrder(orderList) < minCost or minCost == None: minCost = shop.getPriceOfOrder(orderList) minShop = shop return minShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" bestShop = fruitShops[0] lowestCost = bestShop.getPriceOfOrder(orderList) for shop in fruitShops[1:]: if shop.getPriceOfOrder(orderList) < lowestCost: lowestCost = shop.getPriceOfOrder(orderList) bestShop = shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ cost = 1000000 bestShop = None for i in range(len(fruitShops)): shop = fruitShops[i] if (shop.getPriceOfOrder(orderList) < cost): cost = shop.getPriceOfOrder(orderList) bestShop = shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ menor = fruitShops[0].getPriceOfOrder(orderList) tienda = fruitShops[0] for shop in fruitShops: if shop.getPriceOfOrder(orderList) < menor: menor = shop.getPriceOfOrder(orderList) tienda = shop else: None return tienda
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ orderCost = float('inf') cheapestShop = "" # Iterate over all the shops, if the cost of the order is cheaper # then set orderCost and cheapestShop to the one we found for shop in fruitShops: if shop.getPriceOfOrder(orderList) < orderCost: orderCost = shop.getPriceOfOrder(orderList) cheapestShop = shop return cheapestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ minCost = fruitShops[0].getPriceOfOrder(orderList) bestShop = fruitShops[0] for shop in fruitShops[1:]: if shop.getPriceOfOrder(orderList) < minCost: bestShop = shop minCost = shop.getPriceOfOrder(orderList) return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" orderPrice = 0.0 bestPrice = 99999 best = "shop1" for shop in fruitShops: if shop.getPriceOfOrder(orderList) < bestPrice: bestPrice = shop.getPriceOfOrder(orderList) best = shop return best
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" returnShop = fruitShops[0] currentBudget: float = returnShop.getPriceOfOrder(orderList) for shop in fruitShops[1:]: print(currentBudget) print(shop.getPriceOfOrder(orderList)) if shop.getPriceOfOrder(orderList) < currentBudget: returnShop = shop return returnShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ bestPrice=-1 for shop in fruitShops: if bestPrice==-1: bestPrice=shop.getPriceOfOrder(orderList) bestShop=shop elif shop.getPriceOfOrder(orderList)<bestPrice: bestPrice=shop.getPriceOfOrder(orderList) bestShop=shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" bestCost = None bestShop = fruitShops[0] for shop in fruitShops: costOfOrderAtShop = shop.getPriceOfOrder(orderList) if bestCost is None: bestCost = shop.getPriceOfOrder(orderList) if costOfOrderAtShop < bestCost: bestShop = shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" current_price = None best_shop = None for shop in shops: if current_price is None: current_price = shop.getPriceOfOrder(orderList) best_shop = shop if (shop.getPriceOfOrder(orderList) < current_price) and (current_price is not None): best_shop = shop return best_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ # initialize minimum total cost minTotalCost = fruitShops[0].getPriceOfOrder(orderList) # initialize cheapest shop cheapShop = fruitShops[0] # find actual cheapest shop for shop in fruitShops: if (shop.getPriceOfOrder(orderList) < minTotalCost): minTotalCost = shop.getPriceOfOrder(orderList) cheapShop = shop return cheapShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" cheapest_shop = None cheapest_shop = fruitShops[0] cheapest_price = 9999 for shop in fruitShops: if shop.getPriceOfOrder(orderList) < cheapest_shop.getPriceOfOrder( orderList): cheapest_price = shop.getPriceOfOrder(orderList) cheapest_shop = shop return cheapest_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ bestShop = None bestPrice = 0 for shop in fruitShops: if bestPrice == 0 or shop.getPriceOfOrder(orderList) < bestPrice: bestShop = shop bestPrice = shop.getPriceOfOrder(orderList) return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" price = fruitShops[0].getPriceOfOrder(orderList) shop_return = fruitShops[0] for shop in fruitShops: if price > shop.getPriceOfOrder(orderList): price = shop.getPriceOfOrder(orderList) shop_return = shop return shop_return
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ prices = [shop.getPriceOfOrder(orderList) for shop in fruitShops] return fruitShops[prices.index(min(prices))]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ return min(fruitShops, key = lambda shop: shop.getPriceOfOrder(orderList))
def shopSmart(orderList, fruitShops): min_cost, minimum = None, None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) if min_cost == None or cost < min_cost: min_cost, minimum = cost, shop return minimum
def shopSmart(orderList, fruitShops): mcost, itmin = None, None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) if mcost == None or cost < mcost: mcost, itmin = cost, shop return itmin
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ amountsByShops = [(shop.getPriceOfOrder(orderList), shop)for shop in fruitShops] return sorted(amountsByShops)[0][1]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" return min(fruitShops, key=lambda shop: shop.getPriceOfOrder(orderList))
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" # The answer to our problem answer = None # The min price minPrice = float("inf") # iterating through the price for shop in fruitShops: # The price per shop price = shop.getPriceOfOrder(orderList) # Checks if its the first shop if answer == None: answer = shop minPrice = price # Checks if it is a shop with a lower price elif price < minPrice: answer = shop minPrice = price # return results return answer
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" return min((shop.getPriceOfOrder(orderList), shop) for shop in fruitShops)[1]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ # sort the list from least to most expensive and return the first element return sorted(fruitShops, key = lambda shop: shop.getPriceOfOrder(orderList))[0]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" return min( (shop.getPriceOfOrder(orderList), shop) for shop in fruitShops)[1]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ bestShop = {} for shop in fruitShops: bestShop[shop.getPriceOfOrder(orderList)] = shop return bestShop[min(bestShop.keys())]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" cost = 0 for shop in fruitShops: if cost == 0: cost = shop.getPriceOfOrder(orderList) shopname = shop else: if shop.getPriceOfOrder(orderList) < cost: cost = shop.getPriceOfOrder(orderList) shopname = shop return shopname
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ minOrderPrice = fruitShops[0].getPriceOfOrder(orderList) lowest = lambda cheapestShop, shop: shop if shop.getPriceOfOrder( orderList) < minOrderPrice else cheapestShop return reduce(lowest, fruitShops[1:], fruitShops[0])
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ evaluatedShops={} for shop in fruitShops: evaluatedShops[shop]=shop.getPriceOfOrder(orderList) evaluatedShops=OrderedDict(sorted(evaluatedShops.items(), key=lambda t: t[1])) return evaluatedShops.keys()[0]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" prices = [] for shop in fruitShops: prices.append(shop.getPriceOfOrder(orderList)) return fruitShops[prices.index(min(prices))]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" totalPriceList = [] for shop in fruitShops: totalPriceList.append(shop.getPriceOfOrder(orderList)) return fruitShops[totalPriceList.index(min(totalPriceList))]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" Fruit = [] #list for holding fruit for shop in fruitShops: #looping through different shops in fruitShops FruitPrice = (shop.getPriceOfOrder(orderList), shop)#gathering the prices and the shops associated with those prices by containing them in a tuple Fruit.append(FruitPrice)#appends the prices to Fruit[] return min(Fruit)[1]#returns the shop with the minimum value which will be in the (price, shop) [1] spot
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ minimum,deal=None,None for shop in fruitShops: totalCost = shop.getPriceOfOrder(orderList) if totalCost < minimum or minimum==None: minimum, deal = totalCost, shop return deal
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" shopDict = {} for shop in fruitShops: shopDict[shop] = shop.getPriceOfOrder(orderList) ans = min(shopDict,key=shopDict.get) return ans
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ bestStore=None for shop in fruitShops: if (bestStore==None): bestStore=shop elif(bestStore!=None): bestStore=shop if shop.getPriceOfOrder(orderList)<bestStore.getPriceOfOrder(orderList) else bestStore return bestStore
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" fruitshop = fruitShops[0] for shop in fruitShops: if shop.getPriceOfOrder(orderList) <= fruitshop.getPriceOfOrder(orderList): fruitshop = shop return fruitshop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" smallestCost, cheapestShop = None, None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) if smallestCost == None or cost < smallestCost: smallestCost, cheapestShop = cost, shop return cheapestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ min = float('inf') for shop in fruitShops: price = shop.getPriceOfOrder(orderList) if price < min: min = price cheapest = shop return cheapest
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" totalCosts = [] for shop in fruitShops: totalCosts.append((shop, shop.getPriceOfOrder(orderList))) totalCosts = sorted(totalCosts, key=itemgetter(1)) return totalCosts[0][0]
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ leastExpensive = 9999999.0 for shop in fruitShops: currentOrderPrice = shop.getPriceOfOrder(orderList) if currentOrderPrice < leastExpensive: leastExpensive = currentOrderPrice bestShop = shop return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ bestShopPrice = fruitShops[0].getPriceOfOrder(orderList) bestShopName = fruitShops[0] for shop in fruitShops: currentPrice = shop.getPriceOfOrder(orderList) if currentPrice < bestShopPrice: bestShopPrice = currentPrice bestShopName = shop return bestShopName
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ #return shopSmart2(orderList, fruitShops) cheapest_price = fruitShops[0].getPriceOfOrder(orderList) # Cheapest price holds the current lowest price for shop in fruitShops: price = shop.getPriceOfOrder(orderList) # price is the current price to be checked if price <= cheapest_price: # if price is lower remember the shop and the according price cheapest_price = price cheapest_shop = shop return cheapest_shop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ minOrderCost = None minShop = None for shop in fruitShops: currOrderCost = shop.getPriceOfOrder(orderList) if currOrderCost < minOrderCost or minOrderCost == None: minShop = shop minOrderCost = currOrderCost return minShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ cheapestShop = None cheapestCost = None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) if cheapestCost == None or cost < cheapestCost: cheapestShop = shop cheapestCost = cost return cheapestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" minimum = fruitShops[0].getPriceOfOrder(orderList) for shop in fruitShops: price = shop.getPriceOfOrder(orderList) if price <= minimum: bestShop = shop minimum = price return bestShop
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ "*** YOUR CODE HERE ***" minCost, argMin = None, None for shop in fruitShops: cost = shop.getPriceOfOrder(orderList) if minCost == None or cost < minCost: minCost, argMin = cost, shop return argMin
def shopSmart(orderList, fruitShops): """ orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ min = 0 cheapestShop = "" for shop in fruitShops: current = shop.getPriceOfOrder(orderList) if min == 0 or min > current: min = current cheapestShop = shop return cheapestShop
def shopSmart(orderList, fruitShops): if fruitShops: shopPrices = fruitShops[0].getPriceOfOrder(orderList) cshop = fruitShops[0] for shop in fruitShops: temp = shop.getPriceOfOrder(orderList) if temp < shopPrices: shopPrices = temp cshop = shop print "For orders ", orderList, ", the best shop is", cshop.getName() return cshop else: return None