on slices, negative indices, which are the equivalent procedures?

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Aug 7 11:17:43 EDT 2021


On 6/08/21 12:00 pm, Jack Brandom wrote:
> It seems
> that I'd begin at position 3 (that's "k" which I save somewhere), then I
> subtract 1 from 3, getting 2 (that's "c", which I save somewhere), then
> I subtract 1 from 2, getting 1 (that's "a", ...), then I subtract 1 from
> 1, getting 0 (that's J, ...), so I got "kcaJ" but my counter is 0 not
> -13, which was my stopping point.

You need to first replace any negative or missing indices with
equivalent indices measured from the start of the string.

When you do that in this example, you end up iterating backwards from 3
and stopping at -1.

-- 
Greg



More information about the Python-list mailing list