negative indices for sequence types

Chad Netzer cnetzer at sonic.net
Mon Sep 8 13:52:46 EDT 2003


On Mon, 2003-09-08 at 10:11, dan wrote:

> My explanation of the behavior is correct however.  list[a] always
> equals list[a % len(list)].

Many people pointed out to you that this is NOT true.  In particular,
your version gives you NO bounds checking at all; every 'a' is a valid
index (for len(list) > 0).  The Python behavior DOES give IndexError for
an out of bound a, and that difference is very significant, IMO.

-- 
Chad Netzer






More information about the Python-list mailing list