Python Python Collections (2016, retired 2019) Lists Removing items from a list

.pop() and .insert()

I used .pop and .insert to remove "1" from the list and put the "1" at the front of the list using .insert, but i'm still getting errors

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list.pop(1)
messy_list.insert(0,1)

# Your code goes below here

2 Answers

absolutely; Thanks Jason

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,286 Points

Hi Mathew,

You're on the right track, but the instructions say to remove the [integer] 1 from index 3. You are using pop(), which takes an index as the parameter. Check your code... you're passing in index one into the method instead of index 3. The rest is good.

Nice work! :) :dizzy:

Thanks Jason, is there a way I could do all that in one statement?

Jason Anders
Jason Anders
Treehouse Moderator 144,286 Points

Yes you can. It's just a matter of a little combination. I won't give the answer outright, but an example would be:

my_list.insert(index, my_list.pop(index))

You just pop() as the second param. Make sense?

:)