#K5666. Best Prices Finder
Best Prices Finder
Best Prices Finder
You are given a set of records. Each record represents a purchase option from a store and is provided as three values: store_name
, item_name
, and price
.
Your task is to determine the store that offers the lowest valid price for each item and output a dictionary in the following format:
{ 'item_name': { 'store_name': price }, ... }
Records with a price
of None
should be ignored. In the event of a tie (i.e. multiple stores with the same minimum price), use the first occurring record in the input as the answer.
For example: for an item with valid prices given by $$p=\min(price)$$, output the store and its price.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer
n
, which is the number of records. - The next
n
lines each contain three space-separated values:store_name
(a string),item_name
(a string), andprice
(an integer or the literal stringNone
to indicate a missing price).
outputFormat
Print the dictionary with each item mapped to the store offering the lowest price using the Python dictionary format to stdout. The format should exactly follow this pattern:
{'item_name': {'store_name': price}, ...}## sample
6
StoreA apple 3
StoreB apple 2
StoreA banana 1
StoreB banana 2
StoreA milk 5
StoreB milk 4
{'apple': {'StoreB': 2}, 'banana': {'StoreA': 1}, 'milk': {'StoreB': 4}}