List slicing: need help


#1


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


I believe I've used the right code but it just comes up with this error message "Oops, try again. Did you remember to assign a sliced list to all three variables? Your code caused the following error: global name 'first' is not defined"


I thought that this was right because I reviewed other pages in the forum


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

first  = suitcase[0:2]
middle = [2:5]
last   = [4:7]


#2

slicing in first case is right but in second case the items include is 3rd and 4th but counting starts from 0 so you'll need to write 2:4 and 4:6 instead of 2:5 and 4:7.


#3

You didn't slice from your list. Basically, you're slicing from nothing, which throws an error.


#4

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