Departments With People In Them
Kestrel Labs is signing up for a team-survey tool that bills per department. The first wave of the survey goes to everybody who joined during one particular year — the intake the company wants to hear from, which arrives with the request — and finance needs the roster of departments it is about to pay for, the actual names, so somebody can eyeball the list before signing. The names go into the vendor's setup form in alphabetical order, because that is the order the form's own dropdown uses and checking one list against the other by eye is hard enough already.
That export carries one row per person, so department names repeat — two people who joined in the same year can easily sit on the same team. Ten rows is not ten departments, and reading them off by eye works today and stops working the week the company hires its eleventh person.
Finance wants the departments that actually have somebody from that intake in them — so the answer has to come out of the employee list itself, not from any other table lying around.
employees_df — one row per employee. department is the team they belong to.
| id | name | department | salary | hire_date | manager |
|---|---|---|---|---|---|
| 1 | Ava Chen | Engineering | 145000 | 2021-03-14 | None |
| 2 | Ben Ortiz | Engineering | 118000 | 2022-06-01 | Ava Chen |
| 3 | Cara Novak | Engineering | 121000 | 2023-01-10 | Ava Chen |
| 4 | Deshawn Lee | Sales | 95000 | 2020-09-23 | None |
| 5 | Elin Kask | Sales | 88000 | 2022-11-05 | Deshawn Lee |
| 6 | Farid Amiri | Marketing | 76000 | 2023-04-18 | None |
| 7 | Grace Kim | Data | 132000 | 2021-07-30 | None |
| 8 | Hugo Silva | Data | 110000 | 2023-02-14 | Grace Kim |
| 9 | Ines Duarte | Data | 104000 | 2023-08-01 | Grace Kim |
| 10 | Jonas Weber | Sales | 91000 | 2021-12-19 | Deshawn Lee |
Input
The DataFrame above is already built for you — the employee rows are not read from input. What does arrive is a single line holding the intake year, as four digits. hire_date opens with the year in that same four-character shape.
Task: Print a Python list of the distinct department names of the employees hired during that year, in alphabetical order. Each name appears once, however many of that year's joiners are in it. If nobody joined that year, print an empty list.
Example: if the whole intake sat in two departments, the output would look like ['Facilities', 'Legal'].
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in