[Tutor] range as a not-quite-iterator

Jim Mooney cybervigilante at gmail.com
Sun Aug 4 04:01:11 CEST 2013


On 3 August 2013 18:27, Amit Saha <amitsaha.in at gmail.com> wrote:

Oh, he clearly contradicts himself:

>>> R = range(10)                # range returns an iterator, not a list
>>> R
range(0, 10)
>>> I = iter(R)                  # Make an iterator from the range

He's saying R is an iterator, then he's saying iter makes it into an
iterator. It makes no sense to make an iterator into an iterator, so
the wording is wrong, somehow. One of the definitions is wrong or the
other one needs qualification. But I'll go by the interpreter, which
is the final judge. Besides, I can list(range(10)) all day long and
not raise StopIteration, so it must not be an iterator, at least
according to my  understanding.

I could have sworn range(10) was returning a range object def <...>
before, when it's now just >>> range(10)
range(0, 10)

in the interpreter, but I may be misremembering something. Or this is
a very recent change to Python. I'm using sys.version_info(major=3,
minor=3, micro=2, releaselevel='final', serial=0)

-- 
Jim
The Curiosity Rover has been on Mars a year Huh? It feels like it
landed, at most, a few months ago. Where in hell is the time going?


More information about the Tutor mailing list