Skip to content
C

Group and Count by Category

Mediumpython

Given a list of students with their course, write a query using GROUP BY to count how many students are enrolled in each course.

Approach: insert every student into a table, then SELECT course, COUNT(*) FROM students GROUP BY course, ordered by course name for a predictable result.

Input: First line: the number of students n. Next n lines: name,course.

Output: One line per course: a tuple (course, count), ordered alphabetically by course.

Input (stdin)

Output

Run your code to see output here...