a pyrex-inspired for-i-from-1-to-n construct backported to Python.Good idea? Bad Idea? PEP?

David Eppstein eppstein at ics.uci.edu
Wed Apr 2 10:42:37 EST 2003


In article <3E8AFB77.38D0EDDF at engcorp.com>,
 Peter Hansen <peter at engcorp.com> wrote:

> I just scanned a few tens of thousands of lines of our code, and as near
> as I can tell only 13 cases out of over 160 instances of "for" loops are
> using range() or xrange().  This backs up my personal feeling that in
> Pythonic code, it's actually rare to iterate over an integer range 
> specified with simple upper and lower bounds like that, and certainly not
> common enough to justify special syntax.
> 
> I can't agree with the desire to make this a special case, when range()
> provides such a simple, clean answer.

On the other hand, when I'm covering dynamic programming in my 
algorithms classes, the lack of an obvious-to-the-uninitiated integer 
loop syntax (which I don't consider range or worse xrange to be) is the 
main obstacle for me from using actual Python instead of pseudocode in 
my examples.

Anyway, we've had enormous debates on this subject in this group for a 
long time, it's probably pointless to go on for too long on it again.  
For what it's worth, Guido seems to share your point of view.

And to answer the original poster's question in the subject, there 
already are several PEPs on the subject, which Guido commented 
negatively on in his "parade of PEPs" so unless he brings up the subject 
again himself I think they are dead.

-- 
David Eppstein                      http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science




More information about the Python-list mailing list