Possible improvement to slice opperations.

Steve Holden steve at holdenweb.com
Mon Sep 5 11:44:17 EDT 2005


Scott David Daniels wrote:
> Magnus Lycka wrote:
[...]
>>>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.
> 
Actually the two are exactly the same thing. Could we argue about 
substantive matters, please? ;-)

>  > 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ñ.
> 
:-) And how would that be pronounced? I understood that "ñ" would only 
appear between two vowels.
> 
>>>   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.
> 
It does have the merit (if you think of it as a merit) of allowing 
someone to write

     a[n, ~n]

to remove n characters from each end of the string. Frankly I'd rather 
deal with the Python that exists now than wrap my head around this 
particular suggestion.
> 
> 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.
> 
Yes, I've been surprised how this thread has gone on and on.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/




More information about the Python-list mailing list