Andrew Li3,268 Points
Great! Now use .remove() and/or del to remove the string, the boolean, and the list from inside of messy_list. When you'
Why doesn't this accept my answer?
for items in messy_list: if type(items) is str: messy_list.remove(items) if type(items) is bool: messy_list.remove(items)
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]] # Your code goes below here messy_list.insert(0,messy_list.pop(3)) for items in messy_list: if type(items) is str: messy_list.remove(items) if type(items) is bool: messy_list.remove(items)
Steven Parker163,471 Points
You're close, but I see two issues:
- there are other types to be removed besides "str" and "bool"
- altering a list while using it for iteration can cause the loop to skip items
For the first issue, you might try reversing the test to keep what you want and remove the rest:
if type(items) is not int:
And for the second, you can iterate using a copy of the list, which can be made with a slice or by using the "copy" method:
for items in messy_list.copy():