List slicing


#1

hi guys,

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)

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

This is crazy ....
Thanks for your help


#2

I got it !
For MIDDLE : the 3] means it goes until the third, but doesn't include it!


#3

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)
print first
print middle
print last


#4

Just had to comment on this :
When the instrucitons say (index zero and one) I would expect it to be this way[0:1]
so in the next line it says index two and three and I would expect it to be this way [2:3]
So when it says index two and three but the answer is 2:4 this is very confusing to me.

suitcase = [“sunglasses”, “hat”, “passport”, “laptop”, “suit”, “shoes”]

The first and second items (index zero and one)

first = suitcase[0:2]

Third and fourth items (index two and three)

middle = suitcase[2:4]

The last two items (index four and five)

last = suitcase[4:6]