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
George Lugo
Python Web Development Techdegree Student 922 PointsWhat's wrong with my code
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]
slice2 = favorite_things
favorite_things = sorted_things
sorted_things.sort(favorite_things)
[MOD: edited code block - srh]
2 Answers
Steve Hunter
57,712 PointsHi George,
A link to the challenge would really help.
From memory, slice2 wants to be the last two elements of favorite_things, that would be something like:
slice2 = favorite_things[-2:]
Then you need to make a copy of favorite_things and store it in sorted_things:
sorted_things = favorite_things[:]
You need the [;] to make a copy else you'll have two variables pointing at the same list.
Then, sort the new list:
sorted_things.sort() # I think - not sure, to be honest
Sorry, I'm not exact on that. I don't have the challenge to play with and I'm be no means a Python developer!!
Shout if you need more, and post me a link to the challenge!
Steve.
prateekmahesh
5,454 PointsHey George Lugo, You can try this.......
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] #I am not sure if you want the first three index values (1,2,3) or the first 4 (1,2,3,4)
slice2 = favorite_things[-2:]
sorted_things = favorite_things[:]
sorted_things.sort()
You need not specify favorite_things inside the brackets because sorted_things is equal to favorite_things
Thank you!!! I hope this helps you
Regards, Prateek Mahesh
Steven Parker
243,656 PointsSteven Parker
243,656 PointsTo enable the most accurate and complete answers, always show your code and also provide a link to the course page you are working with.