Slice confusion : a[n:p] is a list exclude the last element p (thus spoke Dijkstra)

andrew cooke andrew at acooke.org
Mon Apr 28 17:15:06 EDT 2003


Andrew Koenig said:
> Incidentally, Dijkstra's argument about ``natural numbers'' translates
> directly into an argument about pointers in C, which permits a pointer
> to any element of an array, or to a position immediately past the last
> element of an array, but does not allow a pointer to a position before
> the beginning of an array.

otoh, pointers are annoyingly different to iterators (at least in java -
don't know about c++) which start before (you need to call next() to get
the first item).  this has the advantage of allowing iterators over empty
sets (when hasNext() is false immediately), but it's fiddly converting
between the two approaches.

sorry, this is not really python related (well, i guess it also applies to
the new iterator/coroutine stuff if you use them explicitly)

andrew

-- 
http://www.acooke.org/andrew





More information about the Python-list mailing list