l = range(int(1E9))

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun May 3 07:05:40 EDT 2015


On Sun, 3 May 2015 07:40 am, Jon Ribbens wrote:

> On 2015-05-02, BartC <bc at freeuk.com> wrote:
>> So do I, I think, if no-one is willing to admit that the original way of
>> implementing range() was a glaring mistake.
> 
> I think the issue is that nobody else here thinks the "original way"
> of iterating was to use range(), for anything other than extremely
> small ranges.
> 
> For information, it looks like xrange() was added on 26 Oct 1993,
> which pre-dates Python 1.0.

Ah yes, you are right: my searching failed to find xrange in Python 1.0.1,
but it was actually introduced in 1.0.0. This is from the Misc/NEWS file:

* New function xrange() creates a "range object".  Its arguments are
the same as those of range(), and when used in a for loop a range
objects also behaves identical.  The advantage of xrange() over
range() is that its representation (if the range contains many
elements) is much more compact than that of range().  The disadvantage
is that the result cannot be used to initialize a list object or for
the "Python idiom" [RED, GREEN, BLUE] = range(3).  On some modern
architectures, benchmarks have shown that "for i in range(...): ..."
actually executes *faster* than "for i in xrange(...): ...", but on
memory starved machines like PCs running DOS range(100000) may be just
too big to be represented at all...





-- 
Steven




More information about the Python-list mailing list