Loading...
Loading...
Loading...
A staff CSV has the header name,dept. Print each department with its head count, in alphabetical order of department, as dept count.
dept count, sorted by department name.Example
Input
6 name,dept Asha,Sales Ravi,IT Meena,Sales John,IT Zara,HR
Output
HR 1 IT 2 Sales 2
HR 1, IT 2, Sales 2.
Try the problem first. Open one hint at a time.
Count with a dictionary: counts[key] = counts.get(key, 0) + 1.
Loop over sorted(counts) to print in order.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor