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

Noah Harness
Noah Harness
1,383 Points

HELP ME PLEASE

Alright, my list is messy! Help me clean it up! First, start by 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 takes you more than one step, though!

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
for list in messy_list:
    list = messy_list.insert(0, messy_list.pop(3))
return list


# Your code goes below here

4 Answers

andren
andren
28,558 Points

You should avoid making multiple posts for the same issue. Anyway your previous attempt was pretty close, and in this attempt you solved the issue with the previous attempt but introduced a new error.

Your for loop is incorrect, and not actually needed for the task. But you have actually figured out how to format the input method correctly.

If you remove your loop and return statement and just keep the insert code like this:

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

Then you will be able to pass to the next task.

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

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

messy_list.remove("a") messy_list.remove(False)

print(messy_list)

This works too.

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

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