python loops

Steve Holden steve at
Sun Sep 3 13:55:20 CEST 2006

Nicko wrote:
> Fredrik Lundh wrote:
>>Nicko wrote:
>>>... In the case of the idiom "for i in
>>>range(x):..." there absolutely no utility whatsoever in creating and
>>>recording the list of objects.
>>for short lists, both objects create the *same* number of objects.
> This is true for long lists too, if you iterate over the full range,
> but what I wrote was "creating and recording". The range() function
> generates a variable-sized, potentially large object and retains all of
> the items in the range while xrange() generates a fairly small, fixed
> sized object and only hangs on to one item at a time.  Furthermore,
> it's not at all uncommon for loops to be terminated early. With range()
> you incur the cost of creating all the objects, and a list large enough
> to hold them, irrespective of if you are going to use them.
>>if you cannot refrain from pulling arguments out of your ass, you not
>>really the right person to talk about hygiene.
> I'm impressed but your mature argument. Clearly, in the face of such
> compelling reasoning, I shall have to concede that we should all
> generate our range lists up front.
I'm impressed that you think any of this will be news to the effbot, 
whose sagacity is exceeded only by his irritability in the face of 

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list