3 Oct
2014
3 Oct
'14
11:40 a.m.
On Oct 3, 2014 5:22 PM, "Thomas Chaumeny"
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)