Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Isaac Henry
15,541 Pointsi need help with Python> Slices> intro to slices
intro to slices
here are my answers
favorite_things = ['raindrops on roses', 'whiskers on kittens', 'bright copper kettles',
'warm woolen mittens', 'bright paper packages tied up with string',
'cream colored ponies', 'crisp apple strudels']
slice1 = favorite_things[0, 1, 2] slice1[:3]
5 Answers
Isaac Henry
15,541 Pointssteven can you put it in more blunt terms because it doesn't work
Isaac Henry
15,541 Pointswait
Isaac Henry
15,541 Pointsbut isn't it the answer?
Isaac Henry
15,541 Pointsslice1 = favorite_things[1:3]
then how come this does'nt work
Steven Parker
243,318 PointsAs I said before:
-
slice1 = favorite_things[1:3]this gives you the second and third items
- But the challenge wants the "second, third, and fourth items".
Remember the "stop" value of a slice is the index number that the slice will go up to but not including.
Steven Parker
243,318 PointsYou have some extraneous stuff there.
But if we eliminate that first set of braces with the tuple (comma-separated numbers), and also remove the second reference to the variable being created, this would be left
slice1 = favorite_things[:3]
Now at that point you have a valid slice, but the instructions say the slice should include the "second, third, and fourth items", while this slice selects the first, second and third items. So you still need different start and stop values.
Isaac Henry
15,541 Pointsi tried slice1 = favorite_things[:3] i tried slice1 = favorite_things[1:3] i tried slice1 = favorite_things[1, 2, 3]
Steven Parker
243,318 PointsOk, let's examine each of those:
-
slice1 = favorite_things[:3]as I said, this slice gives you the first, second and third items
-
slice1 = favorite_things[1:3]this slice gives you the second and third items
-
slice1 = favorite_things[1, 2, 3]this is not slice syntax
You were pretty close on that second retry. I bet you can revise that one and make it work.
Remember, the challenge wants the "second, third, and fourth items".
Isaac Henry
15,541 PointsIsaac Henry
15,541 Pointsslice1 = favorite_things[0:3] does this work
Steven Parker
243,318 PointsSteven Parker
243,318 Pointsslice1 = favorite_things[0:3]slice1 = favorite_things[:3]Either way gets you the first, second and third items.
But the challenge is to get the "second, third, and fourth items".