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

Jose Ramirez
Jose Ramirez
9,946 Points

removing items from the list

I don't know how to remove the list from a list

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

# Your code goes below here
clean = messy_list.pop(3)
messy_list.insert(0,1)
del messy_list[0]
messy_list.remove("False")
del messy_list[5]

2 Answers

Jose Ramirez
Jose Ramirez
9,946 Points

thank you very much: this is how I did it del messy_list[-1] the last list del messy_list[4] item 4 del messy_list[1] item 1

Anthony Crespo
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Crespo
Python Web Development Techdegree Student 12,973 Points

You delete a list inside another list like you delete a string or a boolean with the index which, is 5 in this challenge.

This is how I did it.

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

# insert in index 0 and pop object in index 3 at the same time
messy_list.insert(0,messy_list.pop(3))
# now the list look like this: [1, 'a', 2, 3, False, [1, 2, 3]]
# you need to delete the object in index 5, 4 and 1 and you can do that in one line
del messy_list[5], messy_list[4], messy_list[1]

If you delete multiple item in the list start from the end of the list cause if you delete the object in index 1 first then the index 4 and 5 are now in index 3 and 4.