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 < email@example.com> wrote:
In : student_school_list Out: [('Fred', 'SchoolA'), ('Bob', 'SchoolB'), ('Mary', 'SchoolA'), ('Jane', 'SchoolB'), ('Nancy', 'SchoolC')]
In : result = defaultdict(list, student_by_school)
In : result.items() Out: dict_items([('SchoolA', ['Fred', 'Mary']), ('SchoolB', ['Bob', 'Jane']), ('SchoolC', ['Nancy'])])
So: <small voice> never mind </small voice>
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 Pythonfirstname.lastname@example.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/