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 trialEnzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points.pop() and .insert()
Here's the question:
Alright, my list is messy! Help me clean it up! First, start by moving the 1 from index 3 to index 0. Try to do this in a single step by using both .pop() and .insert(). It's OK if it takes you more than one step, though!
What am I doing wrong? PLEASE explain in a way that is easy to understand: I am new to this!
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
value_1 = messy_list.pop(3)
value_1.insert(0)
3 Answers
Steven Parker
231,269 PointsYou're halfway there.
Your pop is fine, you remove the item at index 3 and capture the value in your variable "value_1 ".
But when you insert you have the method attached to your variable instead of the list. And insert requires two arguments, the position (which you have correctly as 0), but it also needs the value to insert (your variable).
Ari Misha
19,323 PointsAlright! Try this:
messy_list.insert(0, (messy_list.pop(3)))
Since pop() function removes the last indexed object from your list , we can use the object returned by our pop() function and pass it to insert() function which takes two arguments: Index and object. So yeah we could use the returned object by pop() function and pass it to insert(). Hope that helped (:
f4u57
6,743 Pointsmessy_list.insert(0,messy_list.pop(3))