List slicing: need help


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]


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.


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


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