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

Great! Now use .remove() and/or del to remove the string, the boolean, and the list from inside of messy_list. When you'

How do i delete the list in the list ?!

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list.pop(3)
messy_list.insert(0, 1)
messy_list.remove("a")
messy_list.remove(False)
del messy_list[5,6,7]
Enzie Riddle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points

Ah you are so close! Remember that when you use the del keyword that you must use the item's index to delete it. Since you have already been using the remove method, I recommend you stick with it, but you definitely can complete it either way! Here's an example. Comment back if you're still having trouble!

items = ["apples", 1, "green", True]
del variable[index]
#run the program
items
['apples', 'green', True]

4 Answers

Eric Fernandez
seal-mask
.a{fill-rule:evenodd;}techdegree
Eric Fernandez
Python Development Techdegree Student 3,008 Points

Is there a better way of doing this

 if "a" in messy_list:
    messy_list.remove("a")
if False in messy_list:
    messy_list.remove(False)
if [1,2,3] in  messy_list:
    del messy_list[3] 
messy_list.remove("a")
messy_list.remove(False)
messy_list.remove([1, 2, 3])
David Toops
David Toops
19,151 Points

Here is a more general way to remove non-integer items from an arbitrary list:

for item in messy_list[::-1]: if isinstance(item,int): if isinstance(item,bool): messy_list.remove(item) else: messy_list.remove(item)