Re: question about slicing with a step length

2006-03-09 Thread Terry Reedy
"André" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >Terry Reedy wrote: >> It appears that s[i:j:-1] is s[(j+1):(i+1)] .reverse()'ed. For >> 'numbers', >> this is 10, 9, 8, 7, 6, 5, 4, 3, 2]. Then take every other item. Why >> the >> +1? Don't know and not my intuitive expe

Re: question about slicing with a step length

2006-03-09 Thread Steven Bethard
John Salerno wrote: > Given: > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > can someone explain to me why > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? I've filed a bug report: http://bugs.python.org/1446619 I suggest the following rewording for extended slices: """ To get the sli

Re: question about slicing with a step length

2006-03-09 Thread André
Terry Reedy wrote: > > John Salerno wrote: > >> Given: > > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > can someone explain to me why > > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? > > It appears that s[i:j:-1] is s[(j+1):(i+1)] .reverse()'ed. For 'numbers', > this is 10, 9, 8, 7, 6, 5,

Re: question about slicing with a step length

2006-03-08 Thread Terry Reedy
> John Salerno wrote: >> Given: > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > can someone explain to me why > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? It appears that s[i:j:-1] is s[(j+1):(i+1)] .reverse()'ed. For 'numbers', this is 10, 9, 8, 7, 6, 5, 4, 3, 2]. Then take every other i

Re: question about slicing with a step length

2006-03-08 Thread John Salerno
André wrote: > An extended slice of list x of length n in the form x[j:k:i] selects > every i-th element starting with and including the element at index j This makes it sound like the index of 10 should be inclusive. > When either index is missing or lies outside of the > list bounds, the mini

Re: question about slicing with a step length

2006-03-08 Thread André
Steven D'Aprano wrote: > John Salerno wrote: > > > Given: > > > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > > > can someone explain to me why > > > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? > > I think the documentation is misleading/incomplete when > it comes to negative strides for ext

Re: question about slicing with a step length

2006-03-08 Thread James Stroud
John Salerno wrote: > James Stroud wrote: > >> John Salerno wrote: >> >>> Given: >>> >>> numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> >>> can someone explain to me why >>> >>> numbers[10:0:-2] results in [10, 8, 6, 4, 2]? >>> >>> I thought the first index, whether going forward or backward, was

Re: question about slicing with a step length

2006-03-08 Thread Steven D'Aprano
John Salerno wrote: > Given: > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > can someone explain to me why > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? I think the documentation is misleading/incomplete when it comes to negative strides for extended slices. The relevent sections are h

Re: question about slicing with a step length

2006-03-08 Thread John Salerno
James Stroud wrote: > John Salerno wrote: >> Given: >> >> numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> >> can someone explain to me why >> >> numbers[10:0:-2] results in [10, 8, 6, 4, 2]? >> >> I thought the first index, whether going forward or backward, was >> inclusive. And there is no index of

Re: question about slicing with a step length

2006-03-08 Thread Steven Bethard
John Salerno wrote: > Given: > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > can someone explain to me why > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? I always have trouble with these. Given the docs[1]: """ The slice of s from i to j with step k is defined as the sequence of items w

Re: question about slicing with a step length

2006-03-08 Thread James Stroud
John Salerno wrote: > Given: > > numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > > can someone explain to me why > > numbers[10:0:-2] results in [10, 8, 6, 4, 2]? > > I thought the first index, whether going forward or backward, was > inclusive. And there is no index of 10 in this list, so what is