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

Hi! Sort clean_list using list.sort()

I am stumped,

How do I Sort clean_list using list.sort() via the problem below:

messy_list = [5, 2, 1, 3, 4, 7, 8, 0, 9, -1]

clean_list = messy_list.sort

I have attempted other methods but cannot get to the correct one in order to solve this problem. Please help if you know how! Thank you!! :D

4 Answers

Hi Missy,

I don't see the code for task 1.

You are supposed to do the sorting on clean_list and not messy_list but first you have to create a copy of messy_list using slice syntax and store that in clean_list

Task 1 instructions - "Copy messy_list using slice syntax into a new variable clean_list."

Are you able to figure out how to slice an entire list?

It looks like there was a quiz question that had you get a slice of an entire list.

You can review the syntax in the Teacher's Notes section of this video http://teamtreehouse.com/library/python-collections/slices/introduction-to-slices

You're getting close.

You're missing the slice syntax for your first task.

The notation that you showed for clean_list[:] is what you want to do on messy_list instead.

clean_list = messy_list[:]

This creates a copy of messy_list and stores it in clean_list using slice syntax.

then in the 2nd task you want to sort clean_list not messy_list.

You should call the sort() method on clean_list.

clean_list.sort()

I hope that helps clear it up for you.

Hi Jason!

Thank you for replying back !

Sorry for not being descriptive enough before.... you are only allowed to type a certain amount of characters into the question box for the 1st ? # ahhhhkilllmenow! # jj

but anyway,

Task 1 instructions - "Copy messy_list using slice syntax into a new variable clean_list."

so yes, for the 1st task you are correct, it asked for that specific answer and I listed the answer:

clean_list = messy_list

part 2 of the ? I am stumped on...

I thought it would be:

clean_list = messy_list.sort() ....

I came up with a few other answers such as: clean_list[:] etc but all of the answers I came up with are incorrect.....

.... please help me out if you can, it would be greatly appreciated!!! Thank you so much!!

Hi Jason!

clean_list.sort() worked! Thanks for your help!!!

You're welcome.