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

Diego Dillon
Diego Dillon
655 Points

list

Create a variable name slice that has the second, the third and forth item slice1 = favorite[:] slice1[1:3]

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

2 Answers

Diego Dillon
Diego Dillon
655 Points

Thank you. But still doesn't work:

slice1 = favorite_things[1:3]

it should work

nakalkucing
nakalkucing
12,964 Points

Hey amigo! In the video just before this challenge, Introduction To Slices, at minute 1:28 Kenneth says that if you want a slice from the second to the fifth item you have to write [1:6], because that will stop at the 6th item and return from the second to the fifth. Does that clear up your problem? Let me know if you need more help. :)

nakalkucing
nakalkucing
12,964 Points

Hey Diego! You're making it a bit more complex than it needs to be. :) You make your slice on the same line as you make slice1, and remember that the first item is zero, the item at the oneth index is the second item and so forth. :) Is that clear enough? Let me know if you need more help. :)