Each Day's Favourite

Python for AIMedium+10 XP+10

Each Day's Favourite

Using the same kind of order list as the café project — one dictionary per order with "date" and "item" keys —

Task: write favourite_by_day(orders) that returns a dictionary mapping each date to the item ordered most often that day.

  • If two items tie on a day, choose the one ordered first that day.
  • Return a plain dictionary. No orders gives {}.

Examples

orders = [{"date": "2026-03-02", "item": "tea"}, {"date": "2026-03-02", "item": "latte"}, {"date": "2026-03-02", "item": "latte"}, {"date": "2026-03-03", "item": "cake"}]
returns {'2026-03-02': 'latte', '2026-03-03': 'cake'}
orders = []
returns {}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run