Python 'for' loop is memory inefficient

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Aug 17 07:44:35 EDT 2009


On 01:44 am, http wrote:
>exarkun at twistedmatrix.com writes:
>>Although I think PyPy also recognizes this case and makes it as
>>efficient as using xrange, and does so without breaking any rules.
>
>How can pypy possibly know that the user hasn't assigned some other
>value to "range"?

It doesn't really need to.  The optimization isn't applied when the 
compiler sees the name "range" being called.  It's applied after the 
object the default builtin name "range" is bound to is called.

Jean-Paul



More information about the Python-list mailing list