<p dir="ltr"><br>
On Oct 3, 2014 5:22 PM, "Thomas Chaumeny" <<a href="mailto:t.chaumeny@gmail.com">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>
<p dir="ltr">You could just do:<br>
sum(customer.is_valid() for customer in customers)</p>