[Python-ideas] A meaningful `if counter:`
cool-RR
cool-rr at cool-rr.com
Tue Apr 5 23:46:01 CEST 2011
On Tue, Apr 5, 2011 at 11:34 PM, Bruce Leban <bruce at leapyear.org> wrote:
> According to the documentation
>
> http://docs.python.org/release/3.1.3/library/collections.html#collections.Counter.elements
> c.elements() returns an empty iterator if there are no elements with counts
> > 0.
>
I am aware of the current behavior.
> When you say you want it to be smart, what do you mean besides that?
>
I mean that it will be like `dict.keys`; an object which behaves similarly
to a list but is implemented more smartly. e.g., `len(counter.elements())`
would be implemented as `sum(counter.values())` for better O complexity, and
`counter.elements().__bool__` would be (trivially) implemented. (You
currently can't do a meaningful `if counter.elements()`).
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110405/69aaa488/attachment.html>
More information about the Python-ideas
mailing list