Counter Class -- Bag/Multiset
Giovanni Bajo
rasky at develer.com
Thu Jan 22 20:41:38 EST 2009
On Thu, 22 Jan 2009 10:11:37 -0800, Raymond Hettinger wrote:
> The collections module in Python 2.7 and Python 3.1 has gotten a new
> Counter class that works like bags and multisets in other languages.
>
> I've adapted it for Python2.5/2.6 so people can start using it right
> away:
> http://docs.python.org/dev/library/collections.html#counter-objects
>
> Here's a link to the docs for the new class:
> http://code.activestate.com/recipes/576611/
Hi Raymond,
* I'm not a native speaker, but why use the word "Counter"? A "counter"
to my ear sounds like a number that is increased each time an event
occurs; the website counter, eg, comes to mind. I can understanda its
meaning probably stretches to "an object that counts", but I really can't
think of it as a group of object, or a container of object. Moreover, I
find it a much more useful abstraction the idea of a "multi-set" (that
is, a set where elements can appear with multiple cardinality), rather
than stressing the concept of "counting" how many times each element
appears in the set.
* I find it *very* confusing c.items() vs c.elements(). Items and
elements are synonymous (again, in my understanding of English).
All in all, I think I prefer your previous bag class:
http://code.activestate.com/recipes/259174/
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
More information about the Python-list
mailing list