Real-world use of Counter

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 6 10:51:20 EST 2014


On Nov 6, 2014 1:06 AM, "Rustom Mody" <rustompmody at gmail.com> wrote:
> In studying (somewhat theoretically) the general world of
> collection data structures we see
> - sets  -- neither order nor repetition
> - bags  -- no order, repetition significant
> - lists -- both order and repetition
>
> Sometimes 'bag' is called 'multiset'
> However counter is a weird non-standard name that overloads
> an already overloaded term -- 'Counter' has a very standard meaning in
programming and in hardware design.

"Bag" is also nonstandard. Other nonstandard names for the same type
include list, heap, bunch, sample, weighted set, occurrence set and
fireset. Knuth uses multiset, so let's stick with that.

As for Counter already having meanings in CS, the Python Counter is
compatible with those.

> 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.

The name "Counter" describes the intended use case, not the implementation,
so I think it's fine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141106/e6f121ee/attachment.html>


More information about the Python-list mailing list