Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48250

Re: Newbie: The philosophy behind list indexes

References <f0ef08bc-464d-4d36-b285-ebc3c7ffb337@googlegroups.com>
Date 2013-06-14 22:35 -0700
Subject Re: Newbie: The philosophy behind list indexes
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.3356.1371274509.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Jun 14, 2013 10:26 PM, <ian.l.cameron@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Newbie: The philosophy behind list indexes ian.l.cameron@gmail.com - 2013-06-14 22:21 -0700
  Re: Newbie: The philosophy behind list indexes Chris Rebert <clp2@rebertia.com> - 2013-06-14 22:35 -0700
  Re: Newbie: The philosophy behind list indexes Chris Angelico <rosuav@gmail.com> - 2013-06-15 15:49 +1000
  Re: Newbie: The philosophy behind list indexes Peter Otten <__peter__@web.de> - 2013-06-15 08:42 +0200
  Re: Newbie: The philosophy behind list indexes John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-15 00:19 -0700
  Re: Newbie: The philosophy behind list indexes Olive <not0read0765@yopmail.com> - 2013-06-15 09:44 +0200
  Re: Newbie: The philosophy behind list indexes ian.l.cameron@gmail.com - 2013-06-19 13:46 -0700

csiph-web