[Python-ideas] Where should grouping() live (was: grouping / dict of lists)

Ivan Levkivskyi levkivskyi at gmail.com
Wed Jul 4 06:36:07 EDT 2018


On 4 July 2018 at 11:25, Steven D'Aprano <steve at pearwood.info> wrote:

> On Wed, Jul 04, 2018 at 11:08:05AM +0100, Ivan Levkivskyi wrote:
> > Replying to the question in subject, I think it would be better in
> > collections as a class.
> > Having it just as a function doesn't  buy much, because one can do the
> same
> > with three lines and a defaultdict.
> > However, if this is a class it can support adding new elements, merge the
> > groupeddicts, etc.
>
> defaultdicts support adding new elements, and they have an update method
> same as regular dicts :-)
>

Except that updating will not do what I want. Merging two groupeddicts is
not just `one.update(other)`
Moreover, using just an update with regular dicts will do something
bug-prone, it will add every group
from `other` as an element to the corresponding group in `one`.

--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180704/7feca1fd/attachment.html>


More information about the Python-ideas mailing list