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

Kaci Jenkins
Kaci Jenkins
860 Points

My code flows in Workspaces?

But in the challenge it still says I need to move the 1 to index 0?

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
list_1 = messy_list.insert(0, messy_list.pop(4))
list_1 = messy_list.remove("a")

2 Answers

Wesley Trayer
Wesley Trayer
13,812 Points

A few things wrong, but they'll be easily mended. :)

>>> messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]  # Assign "messy_list"
>>> print(messy_list)
["a", 2, 3, 1, False, [1, 2, 3]]    # So far so good

>>> list_1 = messy_list.insert(0, messy_list.pop(4))  # But here "list_1" is assigned a value, instead of "messy_list" being changed.
>>> print(messy_list)  # Oh, No! "messy_list" has not changed
["a", 2, 3, 1, False, [1, 2, 3]]

>>> print(messy_list[4])  #  Also ".pop(4)" would "pop" "False", not "1", because python starts counting at "0".
False
>>> print(list_1) 
[False, "a", 2, 3, 1, [1, 2, 3]]   # So this is what "list_1" looks like after running the code.

>>> list_1 = messy_list.remove("a")  # This line reassigns "list_1" again, rather than removing "a" from "list_1"
>>> print(list_1)
[2, 3, 1, False, [1, 2, 3]]

>>> messy_list.pop(5)  # And here's a hint, if you need it.
>>> print(messy_list)
["a", 2, 3, 1, False]

Hope this helps!

Hi, Jenkins

Your code should look like this:

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

# Your code goes below here
messy_list.insert(0, messy_list.pop(3))
messy_list.remove("a")
messy_list.remove(False)
messy_list.remove([1, 2, 3])
Greg Kaleka
Greg Kaleka
39,021 Points

Hi Karim,

Please don't just post answers, especially if you don't include any explanation to go along with it. This doesn't help students learn!