xrange question

John Flynn transpicio at yahoo.com.au
Mon May 7 02:01:48 EDT 2001


"Paul Prescod" <paulp at ActiveState.com> wrote in message
news:mailman.989210650.24674.python-list at python.org...
[...]
> xrange gives you a simple way to do a for-loop over a large array. You
> could do a while instead but you can always replace for-loops with while
> loops. But for-loops are usually clearer than while-loops because the
> one statement does variable declaration, initialization and iteration.

Yep, I see your point about the clarity of for-loops.

Out of curiosity, at what point do you find that 'xrange' becomes most
useful? Do you have a rule of thumb, eg. more than, say, 500 iterations uses
an 'xrange' instead of a range? Or does xrange _replace_ range for you in
for-loops?






More information about the Python-list mailing list