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 trialchevano gordon
3,399 Pointsneed help cant figure out how to add the three parameters at once
i know that reversing the list by every three numbers should be like list_name[::-3] since list_name[::-1] reverse the list by one item each time
messy_list = [5, 2, 1, 3, 4, 7, 8, 0, 9, -1]
# Your code goes below here
clean_list = messy_list[:]
clean_list.sort()
3 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsYou have the correct answer (be sure to be slicing messy_list
on Task 3):
# lists.py
messy_list = [5, 2, 1, 3, 4, 7, 8, 0, 9, -1]
# Task 1 of 3
# Copy messy_list using slice syntax into a new variable clean_list.
clean_list = messy_list[:]
# Task 2 of 3
# Sort clean_list using the sort() method.
clean_list.sort()
# Task 3 of 3
# Now, create a variable named silly_list that is every third item, backwards, from messy_list. For example, the first two items in silly_list should be [-1, 8].
silly_list = messy_list[::-3]
Wendy Turner
718 PointsWhy can't you do silly_list = messy_list[9:0:-3]
Chris Freeman
Treehouse Moderator 68,457 PointsGiven the three indexes, start, stop, and step, the stop must be larger than the start or there will be no list to step through:
>>> messy_list[9:0]
[]
>>> messy_list[9:9]
[]
Lisa Burbon
1,030 Pointssilly_list = messy_list[-1::-3]
chevano gordon
3,399 Pointschevano gordon
3,399 PointsHi Chris Freeman,
I did just that and it never worked, let me try again.