Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices Back and Forth

Tony Ahn
Tony Ahn
24,417 Points

Preview indicates that I should be correct, but can't pass

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']

With this list, I'm supposed to make a slice with the last two variables... which I did.

slice2 = favorite_things[::-1][0:2]

But I can't seem to be able to pass :( any help?

slices.py
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[::-1][0:2]

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing terrific! Using slices takes some getting used to. You do have the last two things from that list, but they are in the reverse order. Your slice is ['crisp apple strudels', 'cream colored ponies'], but it should be ['cream colored ponies', 'crisp apple strudels']. Instead of reversing the slice and taking the first two, try starting two from the end and going forward. Remember, the first number is indicative of where you want to start and can also contain negative numbers :smiley:

I feel like you will get there with this hint, but let me know if you´re still stuck! :sparkles: