negative stride list slices

Peter Hansen peter at engcorp.com
Wed Sep 1 23:15:51 CEST 2004


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



More information about the Python-list mailing list