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.
Created on 2011年03月31日 21:40 by cool-RR, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg132708 - (view) | Author: Ram Rachum (cool-RR) * | Date: 2011年03月31日 21:40 | |
I suggest a `Counter.elements_count()` method should be added, that would give the same answer as `sum(counter.itervalues())`. |
|||
| msg132710 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2011年03月31日 21:47 | |
Thanks for the feature request. Py3.3 is a long ways away, so I'll leave this open for a while. Comments in favor: * Precedent with Smalltalk bags that know their total length Comments against: * sum(c.values()) is trivial to write * fattening the API makes it harder to learn and remember |
|||
| msg132711 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2011年03月31日 21:51 | |
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). Otherwise, I think that sum(c.values()) is enough and can be documented as an example in the Counter doc. |
|||
| msg132712 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2011年03月31日 21:58 | |
> 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. |
|||
| msg132719 - (view) | Author: Matthew Barnett (mrabarnett) * (Python triager) | Date: 2011年03月31日 23:50 | |
The name isn't meaningful to me. My preference would be for something like "total_count". |
|||
| msg133088 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2011年04月05日 20:47 | |
After more thought, I've decided to close this feature request. The operation is utterly trivial and isn't worth fattening the API. I see no advantage in `c.total_count()` versus `sum(c.values())`. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:15 | admin | set | github: 55942 |
| 2011年04月05日 20:47:12 | rhettinger | set | status: open -> closed resolution: rejected messages: + msg133088 |
| 2011年04月01日 16:46:46 | eric.araujo | set | nosy:
+ eric.araujo |
| 2011年03月31日 23:50:38 | mrabarnett | set | nosy:
+ mrabarnett messages: + msg132719 |
| 2011年03月31日 21:58:24 | rhettinger | set | messages: + msg132712 |
| 2011年03月31日 21:51:53 | vstinner | set | nosy:
+ vstinner messages: + msg132711 |
| 2011年03月31日 21:47:07 | rhettinger | set | priority: normal -> low messages: + msg132710 |
| 2011年03月31日 21:40:37 | cool-RR | create | |