* Max M [08:38 13/08/02 CEST]:
Nicolas Évrard 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 ?
The sorted_lst[0:5] notation is called a slice, and returns the first 5 elements in the list.Read it as "from and including 0 until but not 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 you program more. It simply fits most problems better than it would if it included the last element. (You would have "1 off" errors constantly in your code)
Indeed ... -- (°> Nicolas Évrard / ) Liège - Belgique ^^