List Slicing, I need a bit of help


This is my code:

suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"]

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

This is the error message:

Oops, try again. It looks like your middle slice is [] instead of ["passport", "laptop"].

What am I doing wrong?


I just fixed the problem never mind!



I have the same problem, how did you manage to fix it?


You see, on his code:

last = suitcase[4:5]

only has a single little mistake. count the items in the list, there are six items in the list. the '[4:5]' in bellzjay's code only print the 5th item in that list since it stops before the 6th item; or stops after the 5th item. So in order to print the last two items -- "suit" and "shoes" --, change the '5' to '6' or delete it completely like this: [4:]

Oh, and please like my anwer!


middle= suitcase[2:4]
last= suitcase[4:]
This is the correct code