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) Lists Redux Manipulating Lists

make the 1 to position 0, you can do this in one step with .pop() and .insert()

python collections

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
the_list= num.pop(1)int.insert(0)

1 Answer

hie tafara.

firstly you need to use your .pop() and .insert() on the your list, that is your prefix in each case should be the_list to indicate that you are peforming these functions on the variable the_list.

now to insert a certain item in a list, we start by indicating the index on which we want to insert our item in this case its o, then we state what it is that we want to insert in this case its 1. But NOTE well, we want to get our one as the result of popping it out of our list and remember pop uses the index of the item. So to get 1 here, since its on index 3 we use

the_list.pop(3)

now to insert the 1 on index 0 we use

the_list.insert(0,the_list.pop(3))

I created a new variable new_list to store our amended list and the resultant code should be

new_list = the_list.insert(0,the_list.pop(3)).

hop I explained it well.

you sure did thanx a lot

glad I could help, don't forget to upvote