IntermediateLists & Dictionaries25 points

Slowest hospital departments at rush hour

A health board investigates long waits in A&E-style departments during certain hours of the day. Each row of patients.csv is one patient visit.

  • patient_id: unique id
  • department: department name
  • arrival_hour: hour of arrival, integer 0 to 23
  • wait_min: minutes waited before being seen

Task: the input is one line with three integers: min_patients start_hour end_hour. Only visits with start_hour <= arrival_hour <= end_hour are used. For every department compute the average wait and the number of such visits. Keep departments with at least min_patients visits and print them one per line as Department: A min (N patients) with A to 1 decimal, sorted by the exact average (not the rounded one) from highest to lowest; departments with exactly equal averages are ordered alphabetically. If no department qualifies print No department qualifies.

Files your program can read

patients.csv261 lines
patient_id,department,arrival_hour,wait_min
P3001,Dermatology,16,47
P3002,Orthopaedics,16,42
P3003,Cardiology,16,57
P3004,Paediatrics,12,38
P3005,Maternity,12,17
P3006,Oncology,15,11
P3007,Emergency,16,11
...

Open them by name, for example open("patients.csv").

Sample test

Input

3 8 17

Expected output

Dermatology: 96.8 min (13 patients)
Cardiology: 60.9 min (22 patients)
Radiology: 53.5 min (11 patients)
Orthopaedics: 52.9 min (15 patients)
Oncology: 33.2 min (12 patients)
Maternity: 31.6 min (22 patients)
Emergency: 28.9 min (14 patients)
Paediatrics: 27.8 min (12 patients)

Your answer is also checked against 5 hidden tests.

Need a hint?

A dictionary from department to a list of waits makes both the count and the average easy.