This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, meador.inge, rhettinger, slwebber
Date 2012-08-08.07:40:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344411627.1.0.477069269576.issue14182@psf.upfronthosting.co.za>
In-reply-to
Content
At its most basic, a Counter is simply a dictionary with a __missing__ method that supplies a default of zero.  It is intentional that everything else behaves as much like a regular dictionary as possible.  You're allowed to store *anything* in the dict values even if those values don't represent numbers.  A consequence is that equality is taken to mean the same a regular dict equality.

The unary-plus is provided as a way to eliminate zeros from a Counter prior to doing a Counter equality test.

Other designs were possible (such as my Bag class mentioned in the docs).  This one was selected for its versatility, but it does present challenges with respect to zeros, negatives, fractions, etc.  I recognize your concern but find it to be at odds with the basic design of the class.  You might be happier with a Multiset class that restricts itself to positive integer counts.
History
Date User Action Args
2012-08-08 07:40:27rhettingersetrecipients: + rhettinger, mark.dickinson, meador.inge, slwebber
2012-08-08 07:40:27rhettingersetmessageid: <1344411627.1.0.477069269576.issue14182@psf.upfronthosting.co.za>
2012-08-08 07:40:26rhettingerlinkissue14182 messages
2012-08-08 07:40:25rhettingercreate