[Python-ideas] Make len() usable on a generator

random832 at fastmail.us random832 at fastmail.us
Sun Oct 12 06:22:21 CEST 2014


On Fri, Oct 10, 2014, at 19:34, Andrew Barnert wrote:
> The if example is a good illustration of this. If a genexpr is a sequence
> iff it has exactly 1 for clause and 0 if clauses

Why not 2 for clause? Won't its length always be the product of the two
inputs, then? (And you forgot if its inputs are sequences)

More to the point, since python isn't statically typed, there's no
reason that user code would have to produce a view (though I'd suggest
it should at least produce an "iterable" that next can't be called
directly on without iter - a paradigm that has worked well for Java and
C#) if it doesn't want to.


More information about the Python-ideas mailing list