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

random832 at fastmail.us random832 at fastmail.us
Fri Oct 10 20:06:20 CEST 2014


On Fri, Oct 10, 2014, at 11:09, Adam Jorgensen wrote:
> I don't think it makes much sense for len() to work on generators and the
> fact that sum() works isn't a good argument.
> 
> Summing the contents of a generator can make sense whereas attempting to
> obtain the length of something which specifically does not define a
> length
> seems a little nonsensical to me...

Why doesn't it define a length? No, hear me out. Is there any reason
that, for example, generator expressions on lists or ranges shouldn't be
read-only views instead of generators?


More information about the Python-ideas mailing list