Newbie: The philosophy behind list indexes

Chris Rebert clp2 at rebertia.com
Sat Jun 15 01:35:06 EDT 2013


On Jun 14, 2013 10:26 PM, <ian.l.cameron at gmail.com> wrote:
> I bet this is asked quite frequently, however after quite a few hours
searching I haven't found an answer.
>
> What is the thinking behind stopping 'one short' when slicing or
iterating through lists?
>
> By example;
>
> >>> a=[0,1,2,3,4,5,6]
> >>> a
> [0, 1, 2, 3, 4, 5, 6]
> >>> a[2:5]
> [2, 3, 4]
>
> To my mind, it makes more sense to go to 5. I'm sure there's a good
reason, but I'm worried it will result in a lot of 'one-off' errors for me,
so I need to get my head around the philosophy of this behaviour, and where
else it is observed (or not observed.)

I find Dijkstra's explanation rather convincing:
http://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html

Cheers,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130614/56db573e/attachment.html>


More information about the Python-list mailing list