Raymond Hettinger added the comment:

> It is my thought that a Counter with all its keys set to zero 
> is as empty as a Counter with no keys

If the counter were a stand-alone multiset or bag class, this might be a 
reasonable thing to do.

However, for better or for worse, the design of the counter is primarily "a 
dict with a __missing__ that returns 0 and adds some handy methods useful in 
the context of dicts being used for counting".   This gives it flexibility, 
simplicity, speed, and makes it more or less substitutable for regular dicts in 
functions that expect regular dicts.  IIRC, this is the basic design that Guido 
endorsed when the idea of a counter was first proposed.

> I agree it's sort of weird, but I feel like fixing it will 
> just break a ton of existing code.

It is sort of weird, but that was the intended behavior (trying to keep the 
counter as dict-like as possible), and you're correct that changing it now 
would risk either breaking or substantially slowing code existing code.

----------
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22533>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to