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 trialJesh Patel
1,252 Pointsslice challenge question 1 of 3.
cant get pass the slice challenge question in "Back and Forth". I am stuck on 1 of 3.
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]
Jesh Patel
1,252 PointsBummer! Didn't find the right things in slice1
. when I type slice1[2:5]
10 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsslice notation is inclusive of the first index and exclusive of the second index, so [2:6] will get items 2,3,4,5.
Alexander Davison
65,469 Pointsso [2:6] will get indices 2,3,4,5 :)
Bakthyar Syed
Courses Plus Student 884 Pointsfavorite_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]
Jesh Patel
1,252 PointsHey Tri Pham that worked. Thanks
Tri Pham
18,671 PointsI 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...).
Jesh Patel
1,252 PointsIts giving me the same reply. "Bummer! Didn't find the right things in slice1".
Tri Pham
18,671 PointsI think the other poster got it wrong. Its not [2:5] but [1:4].
james south
Front End Web Development Techdegree Graduate 33,271 Pointsremember 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.
mully BENDET
Front End Web Development Techdegree Student 3,054 Pointsme
mully BENDET
Front End Web Development Techdegree Student 3,054 Pointssorry that was a mistake
mully BENDET
Front End Web Development Techdegree Student 3,054 PointsTri Pham good explanation
mully BENDET
Front End Web Development Techdegree Student 3,054 Pointshappy coding
Oren Schindler
Python Web Development Techdegree Student 1,098 PointsThe 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....
Tim Betz
15,146 PointsTim Betz
15,146 PointsIt says it wants the second, third and fourth item. You are giving it one more, the fifth as well. Use [2:5]