extended slicing and negative stop value problem

Max maxmoroz at gmail.com
Sun Aug 21 13:27:26 EDT 2011

On Aug 20, 1:40 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> Pardon me for breaking threading, but I don't have Max's original post.

Not sure why; I also can't see it! I'll copy it at the end just in

> On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz <maxmo... at gmail.com> wrote:
> > Would it be a good idea to change Python definition so that a[10, -1, -1]
> I presume you mean slice notation a[10:-1:-1].
> > referred to the elements starting with position 10, going down to the
> > beginning?
> If this was going to be "fixed", the time was probably
> about three years ago, when Python3 was just starting. Now such a change
> will probably need to wait for the hypothetical Python 4000.

Yeah, I was surprised that it didn't bother anyone..

> The usual advice is to do your slicing twice, reversing it the second time:
> a[0:11][::-1]
> # Instead of a[10:-1:-1], which looks like it should work, but doesn't.

It works nicely, but it is 1.3 times slower in my code (I am surprised
the interpreter doesn't optimize this).

More information about the Python-list mailing list