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

Python Python Collections (Retired) Slices Sorting Slices

need 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

lists.py
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
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You 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]

Hi Chris Freeman,

I did just that and it never worked, let me try again.

Wendy Turner
Wendy Turner
718 Points

Why can't you do silly_list = messy_list[9:0:-3]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Given 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]
[]
silly_list = messy_list[-1::-3]