negative "counts" in collections.Counter?

Daniel Stutzbach daniel at stutzbachenterprises.com
Mon Mar 8 15:30:23 EST 2010


On Mon, Mar 8, 2010 at 1:24 PM, Raymond Hettinger <python at rcn.com> wrote:

> Instinct says that conflating two models can be worse for usability
> than just picking one of the models and excluding the other.
>

Toward that end, shouldn't Counter do one (and only one) of the follow?
1) Disallow non-positive counts (like a Multiset/Bag)
2) Allow them when subtracting

In other words, to avoid conflating two models the following two examples
should produce the same output:

>>> c = Counter({'red': 1})
>>> c['red'] -= 2
>>> c
Counter({'red': -1})

>>> c = Counter({'red': 1})
>>> c2 = Counter({'red': 2})
>>> c - c2
Counter()

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100308/8fd6f8f9/attachment.html>


More information about the Python-list mailing list