Omitting Indices (Incorrect explanation given in the lesson)


If you typed my_list[4:8] of the range(1,12)... The output is: [5, 6, 7, 8] ..... <- notice that the first element in the slicing expression is exclusive and the second element is inclusive. The same applies if you typed this: my_list[3: ]... this prints this: [4, 5, 6, 7, 8, 9, 10, 11] or if you typed: my_list[ :5]... the output is: [1, 2,3, 4, 5] .... <- (2nd element inclusive in the slicing expression).

The opposite of this is given in the explanation of the lesson. Isn't that an error or Have I got it wrong? If I did, the outputs I got in the subsequent lessons backs up my explanation above.

The code below is the explanation given in the lesson by Codecademy:

to_five = ['A', 'B', 'C', 'D', 'E']

print to_five[3:]
# prints ['D', 'E'] 

print to_five[:2]
# prints ['A', 'B']

print to_five[::2]
# print ['A', 'C', 'E']


did you keep in mind that lists are zero indexed based? (meaning, counting start at zero)

The explanation of the lessons is right


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.