xrange question

Paul Prescod paulp at ActiveState.com
Mon May 7 00:47:13 EDT 2001


John Flynn wrote:
> 
>...
> 
> Firstly, I can't see how 'xrange' does anything that can't be done more
> efficiently with 'while'. I think xrange must have a purpose I'm not seeing.

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.

[mailed and posted]
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list