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 trialDavid P
Courses Plus Student 1,162 PointsWhat is wrong with my code???
Let's get in some slice practice! Create a new variable named slice1 that has the second, third, and fourth items from favorite_things.
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
slice1 = [1:3]
3 Answers
Steven Parker
231,236 PointsI see two issues:
- the slice numbers in brackets must come directly after the name of the list
- as Kyle pointed out, the "stop" number is the index to stop before
Tapiwanashe Taurayi
15,889 Pointsslice1 = favorite_things[1:4]
Joel Williams
800 PointsSorry to necro this, but just now going through the program. Maybe this would be helpful to others in the future.
I did the same thing and over-complicated it. I wrote mine as:
slice1 = favorite_things[:] slice1[1:4]
When it really just needed to be "slice1 = favorite_things[1:4]" for the challenge. Although, mine wasn't wrong, it was just less concise with an extra step in there.
Kyle Horne
3,843 PointsKyle Horne
3,843 PointsI believe it needs to be slice1 = favorite_things[1:4]
The second element refers to index 1, third element to index 2, and fourth element to index 3. The slice will include index 1 all the way up to but not including index 4.