The Rota Grid

Data with PythonEasy+10 XP+10

The Rota Grid

A café keeps a log of every shift: who worked, which day, and how many hours. A person can work more than one shift on the same day.

The manager wants the hours laid out as a grid: one row per person, one column per day, with each box holding that person's total hours on that day.

Task: write hours_grid(staff, days, hours). Shift i is staff[i] working hours[i] hours on days[i].

  • Return a dictionary with one key per person. Each value is another dictionary, with one key per day that appears anywhere in days, holding that person's total hours on that day as an int.
  • If a person worked no shift on a day, their box for that day is 0.
  • Hours are whole numbers. There is at least one shift.

Examples

staff = ["Ana", "Ben", "Ana", "Cy", "Ben", "Ana"]
days = ["Mon", "Mon", "Tue", "Wed", "Mon", "Mon"]
hours = [4, 6, 5, 8, 3, 2]
returns {'Ana': {'Mon': 6, 'Tue': 5, 'Wed': 0}, 'Ben': {'Mon': 9, 'Tue': 0, 'Wed': 0}, 'Cy': {'Mon': 0, 'Tue': 0, 'Wed': 8}}
staff = ["Jo", "Kai"]
days = ["Sat", "Sun"]
hours = [7, 5]
returns {'Jo': {'Sat': 7, 'Sun': 0}, 'Kai': {'Sat': 0, 'Sun': 5}}

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