fruit_prices is a dictionary with fruit names as keys and prices as values.
Write bin_fruits(fruit_prices) that classifies every fruit into one of three
categories and returns a dictionary with exactly the keys 'cheap',
'affordable' and 'costly' in that order:
cheap -- price less than 3 (not inclusive)affordable -- price between 3 and 6 (both inclusive)costly -- price greater than 6 (not inclusive)Each value is the list of fruits in that category, kept in the order in which
they appear in fruit_prices (a list, so the result is deterministic). All three
keys must be present even when a category is empty.
Example
bin_fruits({'Apple': 2, 'Banana': 4, 'Kiwi': 8}) returns
{'cheap': ['Apple'], 'affordable': ['Banana'], 'costly': ['Kiwi']}.
Implement this function:
def bin_fruits(fruit_prices: dict) -> dict:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: fruit_prices.
Input
{'Apple': 2, 'Banana': 4, 'Kiwi': 8}
Output
{'cheap': ['Apple'], 'affordable': ['Banana'], 'costly': ['Kiwi']}