On Thu, Jun 28, 2018 at 8:25 AM Nicolas Rolin <nicolas.ro...@tiime.fr> wrote:
> I use list and dict comprehension a lot, and a problem I often have is to > do the equivalent of a group_by operation (to use sql terminology). > > For example if I have a list of tuples (student, school) and I want to > have the list of students by school the only option I'm left with is to > write > > student_by_school = defaultdict(list) > for student, school in student_school_list: > student_by_school[school].append(student) > Thank you for bringing this up. I've been drafting a proposal for a better grouping / group-by operation for a little while. I'm not quite ready to share it, as I'm still researching use cases. I'm +1 that this task needs improvement, but -1 on this particular solution.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/