Re: extended slicing and negative stop value problem

2011-08-23 Thread Ian Kelly
On Aug 21, 2011 1:34 PM, Max maxmo...@gmail.com wrote: 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). Have you tried reverse()? I haven't

Re: extended slicing and negative stop value problem

2011-08-21 Thread Max
On Aug 20, 1:40 pm, Steven D'Aprano steve +comp.lang.pyt...@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 case. On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz maxmo...@gmail.com wrote:

Re: extended slicing and negative stop value problem

2011-08-21 Thread Chris Rebert
On Sun, Aug 21, 2011 at 10:27 AM, Max maxmo...@gmail.com wrote: On Aug 20, 1:40 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz maxmo...@gmail.com wrote: Would it be a good idea to change Python definition so that a[10, -1, -1] I

extended slicing and negative stop value problem

2011-08-20 Thread Max Moroz
Would it be a good idea to change Python definition so that a[10, -1, -1] referred to the elements starting with position 10, going down to the beginning? This would require disabling the negative stop value means counting from the end of the array magic whenever the step value is negative. The

Re: extended slicing and negative stop value problem

2011-08-20 Thread Chris Angelico
On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz maxmo...@gmail.com wrote: Would it be a good idea to change Python definition so that a[10, -1, -1] referred to the elements starting with position 10, going down to the beginning? Well, first off I think it's a dangerous idea to change semantics of

Re: extended slicing and negative stop value problem

2011-08-20 Thread Max
On Aug 20, 11:29 am, Chris Angelico ros...@gmail.com wrote: If you're using a variable for the stop value, you just need to set it to an explicit None if it would fall negative: a[10:None:-1] That doesn't work if it's set in a loop or if it's calculated as a formula. For example, this very

Re: extended slicing and negative stop value problem

2011-08-20 Thread Chris Angelico
On Sat, Aug 20, 2011 at 7:52 PM, Max maxmo...@gmail.com wrote: That doesn't work if it's set in a loop or if it's calculated as a formula. For example, this very simple code doesn't work because of the -1 problem. Right, which is what I meant by setting it to an explicit None: if

Re: extended slicing and negative stop value problem

2011-08-20 Thread Steven D'Aprano
Pardon me for breaking threading, but I don't have Max's original post. On Sat, Aug 20, 2011 at 7:20 PM, Max Moroz maxmo...@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