[Python-ideas] Where should grouping() live
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Jul 3 18:44:17 EDT 2018
Steven D'Aprano wrote:
> I propose that a better name which indicates the non-lazy nature of this
> function is *grouped* rather than grouping, like sorted().
+1
> As for where it belongs, perhaps the collections module is the least
> worst fit.
But then there's the equally strong purist argument that it's
not a data type, just a function.
Unless we *make* it a data type. Then not only would it fit
well in collections, it would also make it fairly easy to do
incremental grouping if you really wanted that.
Usual case:
g = groupdict((key(val), val) for val in things)
Incremental case:
g = groupdict()
for key(val), val in things:
g.add(key, val)
process_partial_grouping(g)
--
Greg
More information about the Python-ideas
mailing list