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

Ian Cordasco graffatcolmingov at gmail.com
Fri Oct 3 18:45:00 CEST 2014


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.
>>
>> It is on Python 3 (but not Python 2):
>>
>> $ python3
>> >>> range(100000)
>> range(0, 100000)
>>
>> And I assumed that most discussion for Python-ideas pertained to
>> features for Python 3, am I incorrect in that?
>
>
> You are correct about python-ideas, but range is not a generator in python 3
> either:
>
> Python 3.4.0a0 (default:e9cecb612ff7+, Oct  3 2014, 12:07:42)
>>>> type(range(10))  # not a generator
> <class 'range'>
>>>> type(x for x in range(10))  # a generator
> <class 'generator'>

Ah yeah. All too often I conflate lazy iterators with generators. Nevermind


More information about the Python-ideas mailing list