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

silly_list=messy_list[:0:-3] silly_list=messy_list[len(messy_list):0:-3] not yielding correct answer

what is wrong with below code ?

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()
silly_list=messy_list[:0:-3]

1 Answer

Suresh,

You're close. Remember that slices are [Start : Stop : Step]. You are telling python to start at the 0 index, stop at the 0 index, and somehow give every 3rd number. Slices can also go backwards, so [-2] would give you the second item from the end.

Also remember the defaults. [:] gives you the entire slice, [0 : : 3] gives you from start to the end and give every 3rd item.

Hopefully that is enough hints to get you on the right track. You may also want to check out this python tutorial: (https://docs.python.org/3/tutorial/introduction.html)