# Possible improvement to slice opperations.

Scott David Daniels Scott.Daniels at Acm.Org
Mon Sep 5 15:26:57 CEST 2005

```Magnus Lycka wrote:
> Ron Adam 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:

>>   | 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.

> 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

```

More information about the Python-list mailing list