Raymond Hettinger <raymond.hettin...@gmail.com> added the comment: > It would be interesting to have Counter.elements_count() > if it has a complexity of O(1): if the collections > maintains a total (in a private attribute).
I agree that it would be interesting; however, it would be an implementation disaster. We would have to override (and slow-down) every mutating method in order to maintain the invariant. And as a dict subclass, any C module using PyDict_Setitem() would bypass those methods and still break the invariant no matter what we do. The Counter tool was designed in an open fashion (a simple, fully exposed dictionary with a few handy methods for counting). In that regard, it is much different and more flexible than a traditional Bag class that maintains its data privately. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11733> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com