List Slicing, how is this wrong?(solved)


#1



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


Oops, try again. It looks like your first slice is ["hat"] instead of ["sunglasses", "hat"].


I don't know why this is wrong : (


Replace this line with your code. 

suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"]

first  = suitcase[0:1]  # 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)

print first
print middle
print last


#2

so when slicing a list, there are two values, start and stop:

aList[start:stop]

but the stop value itself is not included, its lesser then (<) the stop value. Not lesser or equal to the stop value (<=)


#3

oh, ok so it wouldn't print the stop, but would print the start?


#4

under the hood, list slicing is very likely a loop (or something similair) which uses lesser then <, loop do include there start values


#5

so it would be

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

based on my explanation, that should be the logic outcome


#7

got it :smile: thanks a lot!


#8