On Thu, Jun 28, 2018 at 4:23 PM, Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
Nicolas Rolin wrote:
    student_by_school = {group_by(school): student for school, student in student_school_list}

In the spirit of making the target expression look like
a template for the generated elements,

   {school: [student...] for school, student in student_school_list}

hmm -- this seems a bit non-general -- would this only work for a list? maybe you would want a set, or???

so could be get a defaultdict comprehension with something like:

{ school: (default_factory=list, student) for school, student in student_school_list }

But I can't think of an reasonable syntax to make that work.

-CHB







 

--
Greg

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--

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