Real-world use of Counter

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 7 00:05:00 EST 2014


On Nov 6, 2014 10:51 AM, "Ian Kelly" <ian.g.kelly at gmail.com> wrote:
>
> On Nov 6, 2014 1:06 AM, "Rustom Mody" <rustompmody at gmail.com> wrote:
> > Calling a bag as counter is inappropriate for an analogous reason
> > to why calling a dictionary as a 'hash' is inappropriate --
> > it confuses an implementation detail for fundamental semantics.
>
> I've never liked the term "bag". In addition to being nonstandard it's
also very nonintuitive. "Multiset" is fine, except that it implies the
collection is a type of set, which the Python Counter is not.

I was thinking about this today, and it seems to me that the Python Counter
is not really even a multiset.

* The size of a multiset would be the count of all the elements; the len of
a Counter is only the number of keys.
* The multiplicity of an element in a multiset is restricted to the natural
numbers; the count of an element in a Counter can be any integer, even
negative.
* In a Counter, a key with a count of 0 is a distinct state from a key not
being present at all; in the latter case the element is not in the Counter,
while in the former case it *is* in the Counter. These states are also
distinct for the purpose of equality.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141106/6cee8620/attachment.html>


More information about the Python-list mailing list