List Slicing - What is wrong with python?


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/1/2?curriculum_id=4f89dab3d788890003000096#


We are expecting three things out of a sliced list and it gives two items, how is this possible?


I expect that the code should be

first = suitcase[0:1]
middle = suitcase[2:3]
last = suitcase[4:5]


Replace this line with your code. 
suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"]

first  = suitcase [0:2]  # The first and second items (index zero and one)
middle = suitcase[2:4]               # Third and fourth items (index two and three)
last   = suitcase[4:6]            # The last two items (index four and five)


#2

no, in case of suitcase[0:2] the 2 is not included. So it as a loop/condition where lesser then i used: <, not lesser then or equal to: <=

same with range:

for i in range(0,2):
   print i

two is also not included (only values lesser then 2)


#3

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