# Possible improvement to slice opperations.

Mon Sep 5 17:48:23 CEST 2005

```Scott David Daniels wrote:

> Magnus Lycka wrote:
>
>>
>>> ONES BASED NEGATIVE INDEXING
>
>
> I think Ron's idea is taking off from my observation that if one's
> complement, rather than negation, was used to specify measure-from-
> right, we would have a simple consistent system (although I also
> observed it is far too late to do that to Python now).  Using such
> a system should not define things as below:

because the only way to extend the indexes past the last item is to not
use 0 along with negative index's.  And once that's done the '~' forms
"just work" without any additional changes.  ;-)

Yes, it may be too late for changing Python's built in indexing. And it
may also be that the majority may rather use it as is, rather than
change it to fix this edge case.

>>>   | a | b | c |
>>>   +---+---+---+
>>>  -4  -3  -2  -1
>
> but rather use a form like:
>  >>   | a | b | c |
>  >>   +---+---+---+
>  >>  ~3  ~2  ~1  ~0
>
>>> The '~' is the binary not symbol which when used
>>> with integers returns the two's compliment.
>
> Actually, the ~ operator is the one's complement operator.

Yes, thanks, my mistake.

>  > For calculated values on the slice borders, you still
>  > have -1 as end value.
> But if you are defining the from-right as ones complement,
> you use one's complement on the calculated values and
> all proceeds happily.  Since this could happen in Python,
> perhaps we should call it Pythoñ.
>
>>>    a[1:~1] -> center, one position from both ends.
>>
>>
>> This is just a convoluted way of writing a[1:-2], which
>> is exactly the same as you would write today.
>
>
> Actually, a[1 : -1] is how you get to drop the first and
> last characters today.  I suspect you knew this and were
> just a bit in a hurry criticizing a lame-brained scheme.
>
> -Scott David Daniels
> Scott.Daniels at Acm.Org

```