easy +10 pts

Average Salary by Department

Compute average salary per department from employee records.

Write a function `average_salary_by_dept(employees)` that takes a list of employee records. Each record is a tuple `(name, department, salary)` where `name` is a string, `department` is a string, and `salary` is a number (int or float). The function should return a dictionary where keys are department names and values are the average salary of all employees in that department, rounded to two decimal places. Departments that appear in the input must appear in the output. The order of keys does not matter. If the input list is empty, return an empty dictionary.

Constraints

- 0 <= len(employees) <= 10^5 - Each salary is a finite numeric value (int or float). - Department names are non-empty strings. - Average must be rounded to two decimal places using standard rounding.

Example

>>> average_salary_by_dept([("Alice", "Engineering", 90000), ("Bob", "Engineering", 110000), ("Carol", "HR", 70000)])
{'Engineering': 100000.0, 'HR': 70000.0}
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use a dictionary to accumulate total salary and count per department.
After collecting totals, compute each department's average by dividing the sum by the count.
Use the round(value, 2) function to round to two decimals.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.