Common and Unique Students
Given two lists of student names enrolled in two different courses, find the students enrolled in both, and the students enrolled in only one of the two courses.
Approach: put each course's names into a set, then use intersection() for students in both courses and symmetric_difference() for students in exactly one. Print each result sorted alphabetically (comma-separated) so the output is always in a predictable order.
Input: Two lines, each a comma-separated list of student names — the first course's roster, then the second's.
Output: Two lines: Both: <sorted, comma-separated names, or None> Only one: <sorted, comma-separated names, or None>
Aditi,Rohan,Zara Rohan,Karan
Both: Rohan Only one: Aditi, Karan, Zara
- 1 <= students per course <= 200
- Names contain no commas.
Hint 1
a & b (or a.intersection(b)) gives students enrolled in both courses.
Hint 2
a ^ b (or a.symmetric_difference(b)) gives students enrolled in exactly one of the two.
Hint 3
Sort each result with sorted(...) before printing — sets have no guaranteed order, so sorting keeps the output consistent every run.
Turn each course roster into a set. coursea & courseb (intersection) gives students in both; coursea ^ courseb (symmetric_difference) gives students in exactly one. Because plain set iteration order isn't guaranteed, sort each result before joining and printing so the output is deterministic.