Misleading description of [i:j:k] slicing?

Raoul Gough RaoulGough at yahoo.co.uk
Thu Aug 21 13:56:38 EDT 2003


Christos "TZOTZIOY" Georgiou <tzot at sil-tec.gr> writes:

> On Thu, 21 Aug 2003 17:12:28 GMT, rumours say that Michael Hudson
> <mwh at python.net> might have written:
>
>>>   "The slice of s from i to j with step k is defined as the sequence
>>>   of items with index x = i + n*k such that 0 <= n < abs(i-j). [...]"
>
> Basically, it's 0 <= n < abs(i-j)//k, right?

I didn't know about // (silly me) but it looks like a good way to
go. Your alternative formulation still doesn't give the right
behaviour for negative values of k. e.g.

s[4:0:-1]. i.e. i=4, j=0, k=-1 so 0 <= n < -4 ??

or, indeed, for positive k and j<i (should return an empty sequence).

-- 
Raoul Gough
"Let there be one measure for wine throughout our kingdom, and one
measure for ale, and one measure for corn" - Magna Carta




More information about the Python-list mailing list