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 trialmissfit
18,561 PointsHi! 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
Jason Anello
Courses Plus Student 94,610 PointsHi 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?
missfit
18,561 PointsHi 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!!
missfit
18,561 PointsHi Jason!
clean_list.sort() worked! Thanks for your help!!!
Jason Anello
Courses Plus Student 94,610 PointsYou're welcome.
Tony McCabe
4,889 Pointsclean_list.sort()
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsIt 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
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou'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.