Problem with the List Slicing Guide


For whatever reason, this is the code that is required to pass this module:

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

# The first and second items (index zero and one)
first = suitcase[0:2]

# Third and fourth items (index two and three)
middle = suitcase[2:4]

# The last two items (index four and five)
last = suitcase[4:6]

It still throws an error at the bottom when you click run, but the check passes and it lets you proceed. This might be why people feel like they aren’t learning anything.

All of the variables have to be wrong in order to pass this course:

first should be:

first = suitcase[0:1]

second should be:

middle = suitcase[2:3]

last should be:

last = suitcase[4:5]

Its unfortunate that I’m missing a few courses because I didn’t go pro… but then again, how much am I really missing?


i put the correct code (you posted) here:

it working correctly

nope, it shouldn’t, see;

now first only contains the first item, it should contain first and second item. List slicing does not include its stop value, it contains values from indexes lesser then (<) the stop value, not lesser then or equal to (<=) the stop value


Ah, nice.

Thank you for the explanation!


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