Python Python Collections Lists Removing items from a list

Messy List

I bailed this one real bad, help me through please

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

for letter in messy_list
    if letter != 3:
        item = messy_list.pop(3)
        messy_list.insert()
        else letter.insert(0)

2 Answers

Mark Fawcett
Mark Fawcett
12,276 Points

Am I right in thinking that you have to move the number 1 to the beginning of the list?

Could you do it like this?

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

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

Hi Tapiwa,

Mark's got it. The thing about your code is that you're using .insert, but you're not telling it WHAT to insert. You can't just say .insert() or .insert(0) ... if you use insert, you need two arguments, where to insert and what to insert. You popped the fourth item in the list and put it into the variable item, which is great -- but the other lines of your code have no idea that item is what they're supposed to be inserting....