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 trialNikhil Rai
15,391 Pointsmy program is not going further please help!!
Hi,
I got a new challenge in Pythom collection and I did the program (it runs and gives the right result)... however the system is not letting me move forward saying list doesn't have right items.
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 = messy_list[len(messy_list)+1:0:-3]
1 Answer
Gunhoo Yoon
5,027 PointsWhy would you want to do messy_list[len(messy_list)+1:0:-3]
When you can just do messy_list[::-3]
messy_list[len(messy_list)+1:0:-3]
returns [-1, 8, 3]
messy_list[::-3]
returns [-1, 8, 3, 5]
messy_list[len(messy_list)+1:0:-3]
This translates to 3 steps backward from index 11 to index 1. Index 11 does not exist but in this case Python won't complain and just use last item which is -1 and since it stops before index 0 your list will look like [-1, 9, 0, 8, 7, 4, 3, 1, 2] which misses item 5.
Nikhil Rai
15,391 PointsNikhil Rai
15,391 PointsOoops!! Didn't notice this simple thing .... thanks a lot for help!! Cheers