[Python-Dev] PEP 201, zip() builtin

Andrew Dalke dalke at acm.org
Sat Jul 29 02:10:30 EDT 2000


Guido van Rossum wrote:
>There are a few
>well-known cases where xrange() is to be preferred over range(), but
>in *most* cases, I claim, range() performs well enough.  Note that I'm
>not saying that range() is faster than xrange() -- I am saying that it
>is *fast enough* for typical usage.

Though to point out, I've seen one code base where xrange was used
extensively, because there is no time when xrange will fail miserably
while there are cases where range will fail outright, as with very
large data sets.  The most important question for them was not
performance but the implied restriction on the data size.

Since people in the same shop use the same idioms, it's hard to make
estimates as to the numbers that often use xrange over range, but it
seems to be about 5% (let's say +5% and -3% for error bars).

Mind you that the manuals and many of the existing programs are
based off of your work, so there is going to be an implicit bias in
being consistent with your way of doing things.  The people who use
xrange not only have to think it's appropriate for the data set, but
have to justify having "non-standard" code.  Thus, those 5% are not
to be compared with the 95% who use range but the lesser number who
use range over xrange despite knowing about its deficiencies.

Me, I'm one of that subset of the 95% - I use range even knowing
about is deficiencies and only rarely use xrange.  But even better,
I usually end up implementing a list-like forward-iterator for large
data sets - that is, roll my own xrange.  So I would mostly use
zip and only rarely use xzip.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list