On Mon, Oct 14, 2019 at 5:41 PM Serhiy Storchaka <storch...@gmail.com> wrote: > > 14.10.19 03:47, Chris Angelico пише: > > Though a set.__setitem__() method might be helpful here. If you set an > > item to any truthy value, it is added to the set; set it to a falsy > > value and it will be discarded (without error if it wasn't there, so > > assignment in this way is idempotent). That would make them more > > similar to collections.Counter, which can be seen as a multiset of > > sorts. > > It would be a fundamental difference from dict and Counter. > > c = Counter() > c[1] = 0 > assert 1 in c
It doesn't guarantee that if you do any set-like operations, though. c = Counter() c[1] = 0 c |= Counter() # a no-op if thinking set-wise assert 1 not in c So if we're talking analogies with sets, there's no inherent problem with setting-to-zero meaning "remove". ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KLNU5WMPLAD3WG5GGRY6HROPDMQQ4F7A/ Code of Conduct: http://python.org/psf/codeofconduct/