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.
On Fri, Oct 3, 2014 at 5:40 PM, Todd
On Oct 3, 2014 5:22 PM, "Thomas Chaumeny"
wrote: 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.
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:
valid_customers = len(customer for customer in customers if customer.is_valid())
that would be useful.
You could just do: sum(customer.is_valid() for customer in customers)
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/