highest_bid = 0 winner = None for bidder in bid_log: bid_amount = bidder["bid"] if bid_amount > highest_bid: highest_bid = bid_amount winner = bidder print(f"The winner is {winner['name']}")
highest_bid = 0 ## assuming bids are greater than 0, this is a good initialization value winner = None ## another sensible initialization value for bidder in bid_log: ## this is a loop over the items of the list, every item is a dictionary, e.g. { "Name" : "Bob", "bid" : 100 } bid_amount = bidder["bid"] ## retrieve the bid from the current dictionary if bid_amount > highest_bid: ## if the bid is greater than the (current) maximum then... highest_bid = bid_amount ## update the current maximum bid value winner = bidder ## keep track of the relative bidder print(f"The winner is {winner['name']}") ## eventually output the result
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)