Every Member's Clubs

Python for AIHard+10 XP+10

Every Member's Clubs

A sign-up sheet records (name, club) tuples, one per sign-up. Some students signed up for the same club twice by mistake.

Write clubs_by_member(signups) that returns a dictionary of each student's name to a sorted list of their clubs, with no repeats.

  • An empty sheet gives an empty dictionary.

Examples

signups = [('ada', 'drama'), ('bo', 'chess'), ('ada', 'chess'), ('ada', 'drama')]
returns {'ada': ['chess', 'drama'], 'bo': ['chess']}
signups = [("cy", "art"), ("bo", "music"), ("cy", "music"), ("bo", "music")]
returns {'cy': ['art', 'music'], 'bo': ['music']}
signups = []
returns {}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run