<div dir="ltr">In that case it works because boolean values will be converted to 0/1 but you have to force the construction to generate booleans. Also, that generates intermediate additions at each step which might make it slower than a fast iteration until exhaustion.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 3, 2014 at 5:40 PM, Todd <span dir="ltr"><<a href="mailto:toddrjen@gmail.com" target="_blank">toddrjen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr"><br>
On Oct 3, 2014 5:22 PM, "Thomas Chaumeny" <<a href="mailto:t.chaumeny@gmail.com" target="_blank">t.chaumeny@gmail.com</a>> wrote:<br>
><br>
> Yes, it has to exhaust the generator to find the length, but that also is what list(generator) or sum(generator) have to do and yet they are allowed constructions.<br>
><br>
> Actually I don't think that calling len(generator) would be very useful with a generator variable, but with an "anonymous" generator using a comprehension like:<br>
> valid_customers = len(customer for customer in customers if customer.is_valid())<br>
><br>
> that would be useful.</p>
</span><p dir="ltr">You could just do:<br>
sum(customer.is_valid() for customer in customers)</p>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br></div>