Derive fruit prices from fruit mix prices

You see a person selling mixes of fruits in nets, where each net has unique contents and price. There is no weighting machine; everything is sold in bulk, but the fruits of each type seem to have approximately equal size and weight. You would like to know the approximate prices of each fruit, but to learn about the fruit quantities in each net, you decide to buy all five nets.

import numpy as np from collections import OrderedDict fruits = ['apples', 'oranges', 'lemons', 'kiwi', 'mango'] bags_of_fruits = np.array([ [2, 4, 2, 2, 1], [4, 1, 1, 4, 2], [3, 3, 1, 3, 1], [1, 4, 3, 3, 2], [2, 1, 1, 4, 1] ]) bag_prices_euro = [4.80, 4.50, 4.20, 6.10, 3.10] fruit_prices = np.linalg.solve(bags_of_fruits, bag_prices_euro) fruit_prices_dict = OrderedDict([(fruit, float("%.3f" % price)) for fruit, price in zip(fruits, fruit_prices)]) print(fruit_prices_dict) # OrderedDict([('apples', 0.267), ('oranges', 0.5), ('lemons', 0.533), ('kiwi', 0.167), ('mango', 0.867)]) print(fruit_prices_dict['oranges']) # 0.5 (euro)

This seller seems to appreciate the lemons slightly more than the oranges.