[Zope] What is lst[0] ??

Max M maxm@mxm.dk
Tue, 13 Aug 2002 08:38:11 +0200


Nicolas =C9vrard wrote:

> But I wonder why should I use sorted_lst[0:5] to have 5 elements since
> there is in fact 6 elements in it ?? I suppose sorted_lst[0] is some
> kind of a dummy element to stock some informations ... Am I right ?=20

The sorted_lst[0:5] notation is called a slice, and returns the first 5=20
elements in the list.Read it as "from and including 0 until but not=20
including 5." It only returns 5 elements.

While this seems intuitive at first glance, you will get to like this as=20
you program more. It simply fits most problems better than it would if=20
it included the last element. (You would have "1 off" errors constantly=20
in your code)

regards max M

--=20

"Sorry I would Really Like To Help More On This Project,
But Am To Busy Doing Paid Work On A Tight Deadline"
    Max M