Tutorial creates confusion about slices

Steve Holden steve at holdenweb.com
Thu Apr 26 10:23:33 EDT 2007


Michael Hoffman wrote:
> Neil Cerutti wrote:
>>> On Apr 23, 1:38 pm, Antoon Pardon <apar... at forel.vub.ac.be> wrote:
>>>> The following is part of the explanation on slices in the
>>>> tutorial:
>>>>
>>>> The best way to remember how slices work is
>>> ...
>>>>   +---+---+---+---+---+
>>>>   | H | e | l | p | A |
>>>>   +---+---+---+---+---+
>>>>   0   1   2   3   4   5
>>>>  -5  -4  -3  -2  -1
>  >
>> I object only to the word "best". I don't like the above model
>> because it divorces the indexes that appear in subscripts from
>> those that appear in slices. I 't find it complicated to think:
>> a[2:4] is the contiguous slice of elements starting at the gap
>> between element 1 and 2, and ending at the gap between element 3
>> and 4. I've always found thinking of [2:4] as a half-open range
>> much easier.
>>
>> I suppose the above model could avoid this notational problem if
>> you say that a[k] means the one element slice a[k:k+1]
>> (technically true for strings, but false for lists), rather than
>> ever thinking of item indexes as pointing directly at an item.
>>
>> So I vote that the word "best" be removed.
> 
> I agree. It would be better to say that, "One way to help you understand 
> how slices work is to think of..."

I have just checked in that change.

regards
  Steve
-- 
Steve Holden       +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com




More information about the Python-list mailing list