One Column per Line

Data with PythonMedium+10 XP+10

One Column per Line

shops.plot() draws one line per column, with the row labels along the bottom. But the café chain's data comes as a long list: one record per shop per day, and sometimes a shop sends two records for the same day.

Task: write lines_per_shop(days, shops, visitors, day_order). Record i says shop shops[i] had visitors[i] visitors on day days[i].

Return a dictionary with one key per shop. Each value is that shop's line: a list of its total visitors on each day, in the order of day_order.

  • If a shop has several records for the same day, add them up.
  • If a shop has no record for a day, its value that day is 0.
  • Every day in day_order has at least one record, and every record's day is in day_order.

Examples

days = ["Mon", "Mon", "Tue", "Tue"]
shops = ["A", "B", "A", "B"]
visitors = [120, 90, 95, 100]
day_order = ["Mon", "Tue"]
returns {'A': [120, 95], 'B': [90, 100]}
days = ["Tue", "Mon", "Mon", "Wed"]
shops = ["A", "A", "A", "B"]
visitors = [10, 5, 7, 4]
day_order = ["Mon", "Tue", "Wed"]
returns {'A': [12, 10, 0], 'B': [0, 0, 4]}

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