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

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

Shih Kai-Wen
Shih Kai-Wen
613 Points

Challenge

sorry maybe I am too stupid, I have no idea how to revise my code to pass it, can anyone help me??

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[0:2]

1 Answer

As I recall, the challenge was asking for items 2 through 4 from the list. I don't know if it's the same for everyone, however, what you're asking for is the first and second slice.

Remember the count starts at 0. The 'first' item is 0. The second item is 1, etc.

What you have is slices1 = favorite_things[0:2] which will return the value at favorite_things[0] and favorite_things[1]. It stops when it reaches favorite_things[2] and doesn't include it.

In English that's the 'first two items.'

If you wanted the 4th and 5th items you would say favorite_things[3:5].

This would return the value at favorite_things[3], favorite_things[4] and then stop when it reached favorite_things[5] and not include it.

Remember the first number is the starting index. The second number is the ending index which isn't included!