Python Python Collections Lists Removing items from a list

Jose Ramirez
Jose Ramirez
6,980 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
6,980 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
Anthony Crespo
12,904 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.