# What am I doing wrong?

#1

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)

in debug I get "Sunglasses", "hat"
then "passport"
"suit"

#2

here:

``middle = suitcase[2:3] # Third and fourth items (index two and three)``

this will only get the third item, not the fourth item

it will gives values from indexes less then 3, index 3 is not included

#3

Oh, why is that though? Wouldn't it be the third and fourth since third is 2 and fourth is 3?

#4

yes, but for list slicing we have a start and stop value, general syntax:

``yourList[start:stop]``

you picked 2 as start value and 3 as stop value, but list slicing only gets the values from indexes lesser then the stop value, not lesser or equal to the stop value.

#5

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