negative stride list slices

Christopher T King squirrel at WPI.EDU
Wed Sep 1 22:17:20 EDT 2004


On Wed, 1 Sep 2004, Shalabh Chaturvedi wrote:

> Does anyone else find it intuitive to expect that S[b:a:-1] be exactly 
> reverse of S[a:b:1]?

No.  S[a:b:1] includes the start index (a), but excludes the stop index 
(b).  Similarly, S[b:a:-1] includes the start index (b), but excludes the 
stop index (a).  Only if the stop indices were included (or the start 
indices were excluded), thus making the indexing symmetrical, would I 
expect the results to be symmetric.




More information about the Python-list mailing list