Real-world use of Counter

Ian Kelly ian.g.kelly at
Thu Nov 6 16:51:20 CET 2014

On Nov 6, 2014 1:06 AM, "Rustom Mody" <rustompmody at> 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: <>

More information about the Python-list mailing list