List Slicing - Please help, I think this might be a glitch or I'm blind


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/1/2?curriculum_id=4f89dab3d788890003000096#


So I get the following error message-
Oops, try again. It looks like your middle slice is ["passport"] instead of ["passport", "laptop"].


So I think this might be a glitch because it's in the same format as all the other lines that work correctly. Then again I could just be skipping right over something so please point it out to me if that is the case.


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)


#2

Your first slice has two strings in it (at index 0 and 1). The other slices both have only one string in it.

suitcase[2:3] doesn't contain the string at index 3.


#3

Thanks, that helped a lot.


#5

Thank you for bringing this up, I have a same doubt How did this happen ?? There is no 6th index in the list but the correct code is Mentioned below :

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)


#6

Something weird to do with the list, just play around with the index numbers.


#7

my_list[start:stop] does contain the item at the start index, but not the one at the stop index.


#8

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