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 trialsidni ahmed
3,329 Pointsmove the 1 to position 0
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
which medthod do i use?
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi sidni,
You will need to use insert()
with the pop()
inside of the insert function. Remember, when you pop
something out of a list, it will remove it, but it also returns the value.
the_list.insert(0, the_list.pop(3))
So, here we are calling the insert function on the_list
. Inside the parenthesis, we tell the function that we want to insert at index zero the following item (note the comma). Here you call the pop function on the_list
at index 3 which will remove and return 1
, which will then be inserted into the zero index.
I hope this helps and makes sense. Keep Coding! :)