Python Python Collections Lists Removing items from a list

Karen Shumate
Karen Shumate
12,504 Points

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

What else do I need to do?

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

messy_list.pop(3)messy_list.insert(0, "new") 
adam n
adam n
53,663 Points

Try doing this task by writing two lines of code instead of one.

1 Answer

Steven Tagawa
Steven Tagawa
Python Web Development Techdegree Student 4,021 Points

Hi Karen,

You've got all the parts there, they just aren't quite arranged right. Adam has some good advice, which is to start off seeing how it would look on two lines. You'd have to do a line with .pop first, which gets the item you want and stores it in a variable, like

new = messy_list.pop(3)

and then a line inserting your variable at the beginning of the list, like

messy_list.insert(0, new)

(Don't use quote marks there, or else it'll insert the actual word "new" into your list! Make sure you use the same variable that you used for your .pop line.)

Now, if you do two lines like that, it'll pass, so if you want to try doing it in one line, don't test it yet. :) But once you see how it works in two steps, popping your item into new, and then inserting using new, you might be able to see how you can merge the .pop and the .insert together.