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 (2016, retired 2019) Lists Removing items from a list

Messy List

I bailed this one real bad, help me through please

messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]

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

2 Answers

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
.a{fill-rule:evenodd;}techdegree seal-36
Steven Tagawa
Python Development Techdegree Graduate 14,438 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....