Possible improvement to slice opperations.

Ron Adam rrr at ronadam.com
Mon Sep 5 23:33:30 CEST 2005

Steve Holden wrote:

> It's a common misconception that all ideas should be explainable simply. 
> This is not necessarily the case, of course. When a subject is difficult 
> then all sorts of people bring their specific misconceptions to the 
> topic, and suggest that if only a few changes were made the whole thing 
> would be easier to understand.

What misconception do you think I have?

> Unfortunately, while that might make the topic in question easier to 
> understand for some it would make it difficult, and even 
> counter-intuitive, for others. 

True, and that's why asking and getting opinions on a subject is a good 

> As many have said before me, there's a reason why slicing and
> indexing are the way they are. The interfaces were designed by people
> with long years of programming and teaching experience.

No one has yet explained the reasoning (vs the mechanics) of the 
returned value of the following.

    L = range(10)

So far every attempt to explain it has either quoted the documents which 
don't address that particular case, or assumed I'm misunderstanding 
something, or implied it isn't neccisary to do.

It's quite easy to get me to change my mind on something, just show me a 
convincing explanation and I will. :)

> [...]
> You said it quite well yourself:

>> It's easy to think you understand something when you don't. I spend 
>> quite a while figuring this out, And am sure about how it works. If 
>> there are issues with this, then it will probably be in how I describe 
>> it, what words or terminology is used, and weather or not it's the 
>> proper approach.
>> There are actually two distinct proposals here, not just one.
>>      1. Fixing negative strides so they return the slice indexed as 
>> you say they should.
>>      2. Using base one negative index's and picking item from the 
>> right of negative index's instead of the right.
>> They don't both need to implemented, Item 1 could be fixed in 2.5.
> Given that Python has a 1's-complement operator already I don;t see why 
> you can't just leave Python alone and use it, since it seems to keep you 
> happy. If "fixing" item 1 in 2.5 would induce major code breakage, 
> there's less than a snowball's chance in hell it will happen.

I doubt fixing item (1) would induce major code breakage.  As near as I 
can tell, it's rarely, (nearly never), used in forms other than L[::-1].

Item (2) however would require a lot of small changes in index's. 
Mostly changing.. L[:-1] to L[:~1] or to L[:-2].  So no, I don't expect 
one's based indexing to be added any time soon.  It could be useful as a 
function or object in it's own.

> "Professor Einstein, could you tell our readers how general relativity 
> works?"

Actually I can, but it would be off topic for this news group.


> regards
>  Steve

More information about the Python-list mailing list