PEP 276 Simple Iterator for ints (fwd)

Paul Rubin phr-n2001d at nightsong.com
Wed Nov 14 19:15:59 EST 2001


James_Althoff at i2.com writes:
> If not 3), then there is the issue of having to do an extra computation for
> the common case of indexing a sequence as in, e.g.,
> 
>     for i in 0 .. len(sequence)-1:
> 
> OTOH, would it be transparent for "0 .. 5" to mean "0,1,2,3,4"?

0..5 = 0,1,2,3,4 would be awful.  Better would be introduce a new
function, say maxindex(sequence), equal to len(sequence)-1.  Then
you'd say 

   for i in 0..maxindex(sequence):

I guess using len instead of maxindex in this construction would
become a common bug that pylint could check for.



More information about the Python-list mailing list