Re: Possible improvement to slice opperations.
- From: Scott David Daniels <Scott.Daniels@xxxxxxx>
- Date: Mon, 05 Sep 2005 06:26:57 -0700
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@xxxxxxx .
- Follow-Ups:
- Re: Possible improvement to slice opperations.
- From: Ron Adam
- Re: Possible improvement to slice opperations.
- From: Steve Holden
- Re: Possible improvement to slice opperations.
- References:
- Possible improvement to slice opperations.
- From: Ron Adam
- Re: Possible improvement to slice opperations.
- From: Magnus Lycka
- Possible improvement to slice opperations.
- Prev by Date: newbie Q: mouse clicks don't seem to get trapped
- Next by Date: Re: epydoc CLI and many files
- Previous by thread: Re: Possible improvement to slice opperations.
- Next by thread: Re: Possible improvement to slice opperations.
- Index(es):
Relevant Pages
|