List Slicing - What is wrong with python?


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)


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)


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