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 trialMUZ141140 Dennis Pomerai
10,215 Pointswhat I am I doing wrong I get bummer Your messy_list doesn't have the right items
Now ,create a variable silly_list
messy_list = [5, 2, 1, 3, 4, 7, 8, 0, 9, -1]
# Your code goes below here
clean_list = messy_list[:]
clean_list.sort()
silly_list = clean_list[8:-1:-3]
3 Answers
Ian Keith
15,720 PointsYour're close. Say we have a list of ints [0, 1, 2, 3, 4, 5, 6, 7, 8]; your code is telling python to start at the 8th index, which gives us the last item in the list (8 in this example). Your code also tells us to stop at -1, which also gives us the last item in the list, which is 8 again.
Try telling python to start with a negative index and don't forget that slices have defaults. [1 : : 3] would start at 1 and go to the end (length) of the list and give us every third item.
You may find this link helpful: (https://docs.python.org/3/tutorial/introduction.html)
Kenneth Love
Treehouse Guest TeacherIan Keith's answer is a great one but you did find a mistake in the code challenge. I had messy_list
in the error message where I should have had silly_list
. Thanks for finding that!
MUZ141140 Dennis Pomerai
10,215 Pointsmessy_list = [5, 2, 1, 3, 4, 7, 8, 0, 9, -1]
Your code goes below here
clean_list = messy_list[:] clean_list.sort() messy_list = clean_list[10:-3]
Kenneth Love
Treehouse Guest TeacherYou're changing messy_list
. You don't need to ever change messy_list
.