Why doesn't first 3 items in a list need [:2] to select?

Step 5. Select the first 3 items of inventory and save it to the variable first_3 . I tried this, didn’t work. Opened hint and said select first 5 terms.

Hints are not always solutions, just examples or suggestions.

What does your line 7 read?

first_3 = ...

Yes, sorry, the hint was an example, my bad. However, the instructions are misleading; they ask for the first three items. I used first_3 = inventory[:2], which should select the three items with index 0, 1, and 2. The solution was first_3 = inventory[:3], which should, if I’m not mistaken, select the first 4 items (0, 1, 2, and 3).

Like range(), the stop index is excluded from the slice. The above is correct as it takes index 0, 1, and 2.

Oh. Thanks, should’ve paid more attention to the instructions…

1 Like