
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 Out[97]: [('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>
-CHB
--
Christopher Barker, Ph.D. Oceanographer
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
Chris.Barker@noaa.gov _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/