[Edu-sig] Re: In defense of 0, was Re: None potato, one potato, two potato, more..

Kirby Urner urnerk at qwest.net
Mon Jan 5 16:52:05 EST 2004


> > I think of it somewhat differently then.  I think of [0:3] as similar to
> > range(0,3) which means [0,1,2] i.e. the 3 is not included.
> >
> > If we go  [mylist(i) for i in range(0,3)], we get the same as
> > mylist[0:3].
> 
> That doesn't end with differing effect.  [0:3] would still be the
> first three items in my example (and thus the same as range(0,3)
> 

Yes, but in your ruler analogy re mylist[0:3], you deemed it important that
the 3 meant '3 cm' and that '3 cm' was necessary to include the element
starting at 2 cm (i.e. 'c').

I find this confusing because mylist[2] is 'c' is 2 cm (according to your
model), so 3 cm should *not* enter into it when we write mylist[0:3], which
ends at 'c' as well.  

You only need to mention where 'c' *starts* in order to yank it in.  Its
ending point isn't important -- in *either case* (standalone index of [2],
or range-slice of [0:3]).

>From my point of view, mylist[0,1,2] (not real Python syntax) does not
include any '3 cm' and nor does range(0,3) and nor does mylist[0:3].

Negative indexes implicitly subtract from len(mylist).  Whether negative or
positive, the 2nd item in a list is not included (as in range), but we have
the option of leaving it blank (as in mylist[-3:]), in which case we still
get everything through the last element.

Kirby





More information about the Edu-sig mailing list