Practice · Python

Practice Sets & Membership

Use sets for uniqueness and fast membership, and apply union/intersection/difference.

Sets & Membershipwarming python…

Analyze sports lists with set operations

Write a function analyze_sports(team_a, team_b) that receives two lists of sport names (strings). The function must return a tuple of three sets:

  1. The sports appearing in both lists (common).
  2. The sports that appear only in the first list.
  3. The sports that appear only in the second list.

The order of elements does not matter because sets are unordered.

Example

common, only_a, only_b = analyze_sports(['soccer','basketball','tennis'], ['tennis','cricket','soccer'])
# common -> {'soccer', 'tennis'}
# only_a -> {'basketball'}
# only_b -> {'cricket'}
Press Run to see output, or Check to grade against the tests.

Want a whole course built around sets & membership?

Start my path — free

Adaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.