On 15/06/13 07:21, ian.l.came...@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 think it simplify some arithmetic. How many element contain a[2:5]? Answer 5-2=3. And a[:5] contain the first 5 elements.

Olive
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to