PEP 276 Simple Iterator for ints

James_Althoff at i2.com James_Althoff at i2.com
Wed Nov 28 20:20:07 EST 2001


Peter Hansen wrote:
>What am I missing here?  Is the above not just
>a far less sane way of writing the following?
>
>if index >= len(mylist):
>    print 'index out of range'

But "sane" is *such* a loaded term. ;-)

I guess you mean

    if index >= len(mylist) or index < 0:

The double condition is what might prompt some to use the range/xrange
alternative -- along with the fact that

    index in range(len(mylist))

works both in a for-loop and an if-statement.  I see it quite a lot in code
that I come across.  YMMV.

Jim





More information about the Python-list mailing list