5/14


#1

i put this in and i get a error message
suitcase = ["sunglasses", "hat", "passport","laptop", "suit", "shoes" ]

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

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


#2

print out all your variables,

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

and adjust your slices accordingly. :slight_smile:


Edit: in this case you only need to print out the middle variable, in reference to your error.


#3

list slicing has the following general syntax:

aList[start:stop]

but the catch here is that you get the elements lesser then (<) the stop value, not lesser then or equal to (<=) the stop stop value, so [3:4] only gives the third element, not the fourth


#4

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