[Python-ideas] Allow a group by operation for dict comprehension

Chris Barker - NOAA Federal chris.barker at noaa.gov
Thu Jun 28 20:30:04 EDT 2018

> I think you accidentally swapped variables there:
> student_school_list
> vs student_by_school

Oops, yeah. That’s what I get for whipping out a message before catching a bus.

(And on a phone now)

But maybe you could wrap the defaultdict constructor around a
generator expression that transforms the list first.

That would get the keys right. Though still not call append for you.

So maybe a solution is an accumulator special case of defaultdict — it
uses a list be default and appends by default.

Almost like counter...


More information about the Python-ideas mailing list