Count employees by department

Write codeEasy10 min

Your task

An HR export lists one employee per row as a comma-delimited string "name,dept", for example "ava,eng". Write a function that returns a dictionary mapping each department name to the number of employees in it. For example, ["ava,eng", "raj,sales", "mia,eng"] gives {"eng": 2, "sales": 1}.

Examples

dept_headcount(rows: list[str]) -> dict[str,int]
Example 1
Inputdept_headcount(["ava,eng", "raj,sales", "mia,eng"])
Output{"eng": 2, "sales": 1}