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 trialDuc Kevin Nguyen
1,566 Pointswhy this doesn't work??
i think it's right, but it's no. how ?
favorite_things = ['raindrops on roses', 'whiskers on kittens', 'bright copper kettles',
'warm woolen mittens', 'bright paper packages tied up with string',]
slice1 = favorite_things[1:4]
slice2 = favorite_things[5:]
2 Answers
Phil Baker
27,352 Pointslooking at that I think your code is correct but favorite_things
is missing a couple of items:
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[1:4]
slice2 = favorite_things[5:]
Mark Chesney
11,747 PointsHi Duc Kevin Nguyen,
Looks like you're on the task 2 of 3.
Task 2 asks for the last 2 elements of the list. If I want to store the last five elements, I put a negative value before the colon (:
) symbol. Example:
last_five = favorite_things[-5:]
In this example there are few enough to count, but if you needed the last 440 entries of a list that's very long, you can do this: list_xyz[-440:]
Hope this helps!
Steven Parker
231,275 PointsSteven Parker
231,275 PointsPhil Baker — you should post this as an answer instead of a comment, so can can receive votes ans possibly a "best answer" from Duc. If I were a moderator, I would promote it to an answer for you.