# [Python-ideas] [Python-Dev] Inclusive Range

Antoon Pardon Antoon.Pardon at rece.vub.ac.be
Mon Oct 11 13:46:45 CEST 2010

```On Mon, Oct 11, 2010 at 06:25:49AM -0400, Dave Angel wrote:
>  On 2:59 PM, Antoon Pardon wrote:
> >On Sat, Oct 09, 2010 at 01:37:03AM +0000, Steven D'Aprano wrote:
> ><snip>
> >>But the point was that Antoon claimed that there is no numeric value for
> >>the end position that will include L[0] in the reversed slice. My example
> >>shows that this is not correct.
> >I stand by that claim. I think it was fairly obvious that what I meant
> >was that it was impossible to give such a numeric value that would work
> >with arbitrary L.
> >
> >if L2 == list(reversed(L1)) and a and b are in the range 1<  x<= len(L),
> >we have the following invariant.
> >
> >   L1[a:b] == L2[b-1:a-1:-1]
> >
> >However this no longer works if either nr is 0. That means that if a and
> >be are computed values, that may return 0 to indicate which slice you
> >want; that if you want the reversed slice, there is no straightforward
> >way to get that reversed slice with extended slice notation.
> >
> Rather than worrying about how to get from one kind of slice to
> another, consider that for both forward and reversed slices, there
> are edge conditions that are painful.

Why should I not worry. I used to not worry and got stung.

I once without a worry, wrote a testunit that naively depended
on the above invariant. That these edge conditions are painful
for the user of the language is IMO a sign of poor design.

> I think the fact that there are two other idioms that handle it
> makes the "problem" mostly irrelevant.  Either reverse the slice
> after taking it, or use a second slice to chop off zero or more
> items from the end.

No the problem is not mostly irrelevant. Sure it is irrelevant for
those who are well informed and know other ways to get what they
want. But for those who are not that fortunate, it is nasty surprise
waiting to happen.

If there are other ways to get what you want and this way can
produce some nasty surprises, I would think that the way this
was included, was a big mistake.

--
Antoon Pardon

```