Counter Class -- Bag/Multiset

msrachel.e at msrachel.e at
Fri Jan 23 08:37:14 CET 2009

On Jan 22, 5:54 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Giovanni Bajo <ra... at> writes:
> > * I'm not a native speaker, but why use the word "Counter"?
> I agree with this, the new functionality is welcome but I think
> the traditional term "multiset" or "bag" would have been better.

The term counter was what was originally approved.  At first, I didn't
like it but found that it had some advantages.  The main advantage is
that there are *bazillions* of programmers (including some very good
ones) who have never heard the term multiset or bag but have an
intuitive understanding of counting and counters.

Also, in the context of this implementation, "multiset" would not be a
good choice.  The mathematical entity, multiset, is defined with
having a count of one or more.  In contrast, the Counter class allows
counts to go to zero or become negative.  In addition, I worried that
calling it a multiset would suggest that it has a set-like API instead
of a dict-like API.  With the former, you write c.add(elem).  With the
latter, you write c[elem] += 1.  So the name, "multiset" would be

Bike-shed discussions aside (everyone has an opinion of how to name
how do you guys like the functionality?  Do you find it useable in
use cases?


More information about the Python-list mailing list