Counter Class -- Bag/Multiset

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Jan 23 09:24:35 CET 2009


Raymond Hettinger:
> 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.

Very nice. Python std lib is growing more data structures, increasing
the power of a default Python installation. I can remove more and more
modules from my bag of tricks.

I like the name Bag(), it's shorter. Names are important enough.

Are keys restricted to be long and int values only? Or are they
general (referenced) objects + a control of their integral nature?

I think you can add better explanations to this, like an example:
c += Counter() # remove zero and negative counts

Bye,
bearophile



More information about the Python-list mailing list