[Python-ideas] Make len() usable on a generator
Andrew Barnert
abarnert at yahoo.com
Fri Oct 3 19:26:05 CEST 2014
On Oct 3, 2014, at 19:13, Joshua Landau <joshua at landau.ws> wrote:
> On 3 October 2014 17:45, Ian Cordasco <graffatcolmingov at gmail.com> wrote:
>> On Fri, Oct 3, 2014 at 11:32 AM, Alexander Belopolsky
>> <alexander.belopolsky at gmail.com> wrote:
>>> On Fri, Oct 3, 2014 at 12:27 PM, Ian Cordasco <graffatcolmingov at gmail.com>
>>> wrote:
>>>>
>>>>> Builtin range is not a generator.
>>>
>>> You are correct about python-ideas, but range is not a generator in python 3
>>> either:
>>
>> Ah yeah. All too often I conflate lazy iterators with generators. Nevermind
>
> It's not an iterator either:
>
> from collections.abc import Iterator
> isinstance(range(10), Iterator)
> #>>> False
>
> It's just an iterable container.
In a sense, it's like the dict views, or any other sequence, set, or similar container that doesn't directly store its objects but instead created them lazily. It might be nice if we had a generic term for such things.
On the other hand, maybe it's not so critical. I think most of the confusion comes from people who are Python 3 novices but not Python 2 novices (who expect that if range, dict.keys, etc. no longer produce lists, they must instead be producing iterators; new programmers, transplants from Java or Perl, etc. won't have such expectations), and the number of those is dwindling and will continue to do so.
More information about the Python-ideas
mailing list