PEP 276 Simple Iterator for ints

Peter Hansen peter at engcorp.com
Wed Nov 28 20:47:21 EST 2001


James_Althoff at i2.com wrote:
> 
> Jeff Shannon wrote:
> >Better still, and already valid:
> >
> >if index >= len(mylist):
> >    print 'index out of range'
> 
> ... although you would probably want to add the other condition as well:
> 
>     if index >= len(mylist) or index < 0:

Or just:

if not 0 <= index < len(mylist):
    print 'index out of range'

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list