Cherie T3,429 Points
Can't use .remove() to remove the list from inside of messy_list. Why?
Hi there. Going through Challenge Task 2 of 2 in Python Collections on Lists.
For some reason, my code can remove the bool and str but not list... only when using messy_list.remove[1,2,3] does it remove the list. Why is that?
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]] # Your code goes below here messy_list.insert(0,messy_list.pop(3)) for item in messy_list: if item is not int: messy_list.remove(item) messy_list.remove[1,2,3]
Steven Parker170,273 Points
Removing items from an iterable while it is controlling a loop can cause other items in the loop to be skipped over. To prevent this, use a copy of the iterable to control the loop.
Also, I wouldn't expect "
item is not int" to be a viable test. Did you mean to use the "type" function?