I think you cheated a little in your cut-and-paste.  `student_by_school` is not defined in the code you've shown.  What you *did* define, `student_school_list` doesn't give you what you want if you use `defaultdict(list,student_school_list)`.

I thought for a moment I might just use:

[(b,a) for a,b in student_school_list]

But that's wrong for reasons that are probably obvious to everyone else.  I'm not really sure what `student_by_school` could possibly be to make this work as shown.

On Thu, Jun 28, 2018 at 8:13 PM Chris Barker via Python-ideas <python-ideas@python.org> wrote:
In [97]: student_school_list
[('Fred', 'SchoolA'),
 ('Bob', 'SchoolB'),
 ('Mary', 'SchoolA'),
 ('Jane', 'SchoolB'),
 ('Nancy', 'SchoolC')]

In [98]: result = defaultdict(list, student_by_school)

In [99]: result.items()
Out[99]: dict_items([('SchoolA', ['Fred', 'Mary']), ('SchoolB', ['Bob', 'Jane']), ('SchoolC', ['Nancy'])])

So: <small voice> never mind </small voice>



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Python-ideas mailing list
Code of Conduct: http://python.org/psf/codeofconduct/

Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.