Questions regarding design decisions in listobject.c

Gordon McMillan gmcm at hypernet.com
Sun Jun 4 22:50:39 EDT 2000


Courageous wrote:

>Thomas Wouters wrote:

>> Actually, it's very intuitive, if you see the start and end index of
>> the slice not as items, but as the gaps between the items.

>Well, yeah, but [0:3] as "element zero through three, inclusive"
>is about as intuitive as you can get. While I understand completely
>how the current implementation works (reading the source code and
>all, dontcha know), I still fail to see *why* this was chosen.
>I'm presuming there must be some conditions where this particular
>idiom was required or caused for nasty syntactic transformations
>if it wasn't used?

Actually, this being Usenet, you're both wrong! There's nothing "intuitive" 
about either one. It's all what you're used to.

I suspect you haven't used many repetitive slicing algorithms. It boils 
down to being nice because

 lst == lst[:x] + lst[x:]

That is, no horsing around with adding one. Once you get used to it, you'll 
find the "inclusive" way to be clunky and error prone.

- Gordon



More information about the Python-list mailing list