i think i have a solution, you need to know the number of each item in the list and if it is more that the stock count you need to lower your order to match the number of this item in the stock... never mind , here is a code that you can start with and improve in time :
shopping_list = ["apple","pear","pear","pear","orange","banana","banana",
"banana","banana","banana","banana","banana","banana","banana"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
banana_number = food.count("banana")
apple_number = food.count("apple")
orange_number = food.count("orange")
pear_number = food.count("pear")
total = 0
hash_table = {"apple":apple_number,"banana":banana_number,
"orange":orange_number,"pear":pear_number}
for key in hash_table:
if hash_table[key]>stock[key]:
hash_table[key] = stock[key]
else:
hash_table[key] = hash_table[key]
total += prices[key]*hash_table[key]
stock[key] -= hash_table[key]
print total
print stock
if __name__ == '__main__':
compute_bill(shopping_list)
i hope i have helped @Adrian