[Zope] What is lst[0] ??

Nicolas Évrard nicoe@wanadoo.be
Tue, 13 Aug 2002 08:51:01 +0200


--dDRMvlgZJXvWKvBx
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* Max M  [08:38 13/08/02 CEST]:=20
>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.

Yep ! Now that we are in the morning, I wonder how I could have write
such a thing befor even thinking about it ...

The best part is that I use it very often but for some reason my brain
stopped working yesterday near 2 O'clock in the morning ...

Thanks anyway !!

>
>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)

Indeed ...

--=20
(=B0>  Nicolas =C9vrard
/ )  Li=E8ge - Belgique
^^

--dDRMvlgZJXvWKvBx
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9WKxV1fJ5cz1/+2URAktOAJ9nIn2N8FFhABF7ePNOI4dLa3G8TACgzLkI
L+SJIGCNwcGUOWNBAvMuw/Y=
=3Epk
-----END PGP SIGNATURE-----

--dDRMvlgZJXvWKvBx--