efficiency of range() and xrange() in for loops

Steve R. Hastings steve at hastings.org
Thu Apr 6 16:25:04 EDT 2006


On Wed, 05 Apr 2006 22:08:29 -0700, Carl Banks wrote:
>> for i in range(n)
>>
>> into compiled code equivalent to
>>
>> for i in itr
>>
>> where "itr" is a lightweight iterator that returns the same values as
>> iter(range(n)).

> Nope, out of the question for Python 2.x.  Note that the the builtin
> range could be rebound, or a global range could appear in the module,
> at run time.

Ah!  Of course.

Thank you very much for explaining this.
-- 
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha




More information about the Python-list mailing list