List Slicing tutorial bugging me out... :/


#1



Hey guys,
Maybe someone can help me with an issue I am having in one of the tutorials
Any ideas welcome!!

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


As far as I can tell the code is good, but i still get the error message saying "Oops, try again. It looks like your middle slice is ["passport"] instead of ["passport", "laptop"]."


Looks to me like the something in the environment may be ignoring the second index in the list 'middle'.
I'm guessing 'suitcase[2:3]' is the correct way of slicing the middle 2 values in the list suitcase.


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

[included first index : excluded last index]

middle = suitcase[2:4]

last = suitcase[4:6]

# or

last = suitcase[4:]

#3

Wow... I guess the bug was in my brain...
thanks for clearing that up for me!


#4

We can use negative indices as well...

>>> suitcase[-2:]
['suit', 'shoes']
>>>

#5

Good to know...
Thanks!


#7