negative stride list slices

Julio Oña thinmanj at gmail.com
Wed Sep 1 23:23:18 CEST 2004


Slice has three arguments, [begin:end:step]

when doing s[:-3:-1] you are asking the las to elements of the list in
reversed order.

regards.

On Wed, 01 Sep 2004 17:15:51 -0400, Peter Hansen <peter at engcorp.com> wrote:
> Reid Nichol wrote:
> 
> > This was the part that I was refering to:
> >
> >  +---+---+---+---+---+
> >  | H | e | l | p | A |
> >  +---+---+---+---+---+
> >  0   1   2   3   4   5
> > -5  -4  -3  -2  -1
> >
> > Does it not all work the same in practice?
> 
> Can you explain how the above diagram explains David's
> example then:
> 
> >>> s = 'HelpA'
> >>> s[:-3:-1]
> 'Ap'
> 
> I don't find much connection between the diagram and
> where the -3 is actually slicing either.
> 
> -Peter
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Julio



More information about the Python-list mailing list