[Python-ideas] grouping / dict of lists
storchaka at gmail.com
Sat Jun 30 03:57:03 EDT 2018
30.06.18 00:42, Guido van Rossum пише:
> On a quick skim I see nothing particularly objectionable or
> controversial in your PEP, except I'm unclear why it needs to be a class
> method on `dict`. Adding something to a builtin like this is rather
> heavy-handed. Is there a really good reason why it can't be a function
> in `itertools`? (I don't think that it's relevant that it doesn't return
> an iterator -- it takes in an iterator.)
> Also, your pure-Python implementation appears to be O(N log N) if key is
> None but O(N) otherwise; and the version for key is None uses an extra
> temporary array of size N. Is that intentional?
And it adds a requirement to keys be orderable.
I think there should be two functions with different requirements: for
hashable and orderable keys. The latter should return a list of pairs or
a sorted dict if they be supported by the stdlib.
I'm not sure they fit well for the itertools module. Maybe the purposed
algorithms module would be a better place. Or maybe just keep them as
recipes in the documentation (they are just few lines). Concrete
implementation can be simpler than the general implementation.
More information about the Python-ideas