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

slice challenge question 1 of 3.

cant get pass the slice challenge question in "Back and Forth". I am stuck on 1 of 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:6]

It says it wants the second, third and fourth item. You are giving it one more, the fifth as well. Use [2:5]

Bummer! Didn't find the right things in slice1. when I type slice1[2:5]

10 Answers

slice notation is inclusive of the first index and exclusive of the second index, so [2:6] will get items 2,3,4,5.

so [2:6] will get indices 2,3,4,5 :)

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]

Hey Tri Pham that worked. Thanks

I don't think slice1[number1:number2] actually changes the slice1 array but returns a new array. So do slice1=slice1[number1:number2] or just slice1 = favorite_things [number1: number2]. Of course number1 and number2 are your actual numbers (0,1,2...).

Its giving me the same reply. "Bummer! Didn't find the right things in slice1".

I think the other poster got it wrong. Its not [2:5] but [1:4].

remember that 0-based indexing is used, so the first item is index 0, not 1. the second item is index 1 and the fourth item is index 3.

me

sorry that was a mistake

Tri Pham good explanation

happy coding

The issue isn't indexing, it's that it was demonstrated one way, where one makes a copy of the list, and saves that in a variable, which then is sliced. All of the answers provided show a completely different formatting. I still don't understand why creating a copy of favorite_things and then slicing that copy doesn't work? Is it because you simply need to print it? If so, that wasn't demonstrated either....