Speed-up for loops

Aahz aahz at pythoncraft.com
Tue Sep 7 19:39:58 CEST 2010

In article <roy-0EC6F2.08091107092010 at news.panix.com>,
Roy Smith  <roy at panix.com> wrote:
>Imagine that you're looking at some code which was written years ago, by 
>people who are no longer around to answer questions.  In one place, you 
>for i in range(n):
>   blah
>and in another, you see:
>for j in xrange(n):
>   blah
>If you are truly a Python expert, you'll say to yourself, "range and 
>xrange are synonyms", and move on to other things.  If, however, you're 
>not really an expert, you'll look at this and say, "Hmmm, in one place 
>they used range(), and in another they used xrange().  Clearly, there's 
>some reason for the difference, I need to figure out what it is, because 
>that's probably key to my understanding why this code isn't working".  
>So, you spend the next two hours pouring over reference manuals trying 
>to understand the subtle difference, until your friend comes over and 
>says, "You dolt, you just wasted half the afternoon.  They're the same 
>thing.  Move on, this is not the bug you're looking for".

...and if you're a Python guru, you might spend a little bit of time
trying to figure out if the range() is causing the problem due to
allocating a large chunk of memory....
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells

More information about the Python-list mailing list