When I teach the concept of element indexing to novice programmers, a metaphor I use is to think of the indexes and numbers in a ruler. And of the contents in the list (or array, vector, string, etc...), as physical objects that are placed on this ruler - say a pebble or anything. You place the objects between the the numbers - not on their midle. So the first peble is in the space between the 0 and 1 markers. The second is the space between the 1 and 2.
And the last one will be on the space between the 29 and 30 markers, even if the ruler is 30cm long - after the 30, the rule is over, and no other elements can be placed.
That not only helps visualize how elements start at index 0, but also with Python slicing notation, in which the end of the slice denotes the limit up to the elements are picked (and not the last element to be picked).
So, on a list, lst[0:1] will pick all elements between the 0 and 1 markers, and lst[0:28] will pick the elements between those numbers, and the last two elements, between [28:30] are left out.
(on an unrelated note, I hope you do not actually use l
as a variable name - one letter variable names are usually not a good practice, with good sense prevailing, but l
specifically is hard to distinguish from 1
, so it makes the code harder to read)