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


I'm trying to get the 2 middle items and 2 last items from suitcase. Isn't my code correct ?

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)


for list slicing, we have the following syntax:


But for the stop value goes that its lesser then (<) the stop value, not lesser or equal to (<=)

so [2:3] means indexes less then 3. But you also want index 3?


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