a pyrex-inspired for-i-from-1-to-n construct backported to

Lulu of the Lotus-Eaters mertz at gnosis.cx
Wed Apr 2 19:54:08 CEST 2003


Peter Hansen <peter at engcorp.com> wrote previously:
|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().

In my estimation, the enumerate() function introduced in 2.3 will cover
many of those 13 cases too.

In my own code, in the rare case I use range(len(lst)) for a loop, I
still generally index into lst within the body.  As in:

    for i in range(len(lst)):
        if i > ...:
            lst[i] = ...

Or that sort of thing.  I don't like the above construct especially, but
enumerate fixes it.

Admittedly, once in a while I really do want to loop over some integers
as such (i.e. not considered as indices).  But for that, range(N)
doesn't feel unnatural.

Yours, Lulu...

--
---[ to our friends at TLAs (spread the word) ]--------------------------
Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego
White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad
---[ Postmodern Enterprises <mertz at gnosis.cx> ]--------------------------






More information about the Python-list mailing list