<div dir="ltr">It doesn't behave like a generator because it doesn't implement send, throw, or close. Â It's a sequence because it implements: Â __getitem__, __len__ __contains__, __iter__, __reversed__, index, and count.<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 30, 2015 at 2:43 PM M.-A. Lemburg <<a href="mailto:mal@egenix.com">mal@egenix.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 30.09.2015 20:26, Andrew Barnert via Python-ideas wrote:<br>
> On Sep 30, 2015, at 11:11, M.-A. Lemburg <<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a>> wrote:<br>
>><br>
>>> On 30.09.2015 19:19, Neil Girdhar wrote:<br>
>>> I guess, I'm just asking for enumerate to go through the same change that<br>
>>> range went through. Why wasn't it a problem for range?<br>
>><br>
>> range() returns a list in Python 2 and a generator in Python 3.<br>
><br>
> No it doesn't. It returns a (lazy) sequence. Not a generator, or any other kind of iterator.<br>
<br>
You are right that it's not of a generator type<br>
and more like a lazy sequence. To be exact, it returns<br>
a range object and does implement the iter protocol via<br>
a range_iterator object.<br>
<br>
In Python 2 we have the xrange object which has similar<br>
properties, but not the same, e.g. you can't slice it.<br>
<br>
> I don't know why so many people seem to believe it returns a generator. (And, when you point out what it returns, most of them say, "Why was that changed from 2.x xrange, which returned a generator?" but xrange never returned a generator either--it returned a lazy almost-a-sequence from the start.)<br>
<br>
Perhaps because it behaves like one ? :-)<br>
<br>
Unlike an iterator, it doesn't iterate over a sequence, but instead<br>
generates the values on the fly.<br>
<br>
FWIW: I don't think many people use the lazy sequence features<br>
of range(), e.g. the slicing or index support. By far most<br>
uses are in for-loops.<br>
<br>
--<br>
Marc-Andre Lemburg<br>
eGenix.com<br>
<br>
Professional Python Services directly from the Experts (#1, Sep 30 2015)<br>
>>> Python Projects, Coaching and Consulting ... <a href="http://www.egenix.com/" rel="noreferrer" target="_blank">http://www.egenix.com/</a><br>
>>> Python Database Interfaces ...      <a href="http://products.egenix.com/" rel="noreferrer" target="_blank">http://products.egenix.com/</a><br>
>>> Plone/Zope Database Interfaces ...      <a href="http://zope.egenix.com/" rel="noreferrer" target="_blank">http://zope.egenix.com/</a><br>
________________________________________________________________________<br>
2015-09-25: Started a Python blog ... ...     <a href="http://malemburg.com/2015-10-21" rel="noreferrer" target="_blank">http://malemburg.com/<br>
2015-10-21</a>: Python Meeting Duesseldorf ...         21 days to go<br>
<br>
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::<br>
<br>
  eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48<br>
  D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg<br>
      Registered at Amtsgericht Duesseldorf: HRB 46611<br>
        <a href="http://www.egenix.com/company/contact/" rel="noreferrer" target="_blank">http://www.egenix.com/company/contact/</a><br>
</blockquote></div>