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]
Tim Betz
Tim Betz
15,146 Points

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

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

Bakthyar Syed
PLUS
Bakthyar Syed
Courses Plus Student 884 Points

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

Tri Pham
Tri Pham
18,671 Points

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".

Tri Pham
Tri Pham
18,671 Points

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

me

sorry that was a mistake

Tri Pham good explanation

happy coding

Oren Schindler
seal-mask
.a{fill-rule:evenodd;}techdegree
Oren Schindler
Python Web Development Techdegree Student 1,098 Points

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....