
The call to .index() may raise a ValueError if the item is not in the list. So both the .index() and .pop() calls should be in the try block.
The call to .index() may raise a ValueError if the item is not in the list. So both the .index() and .pop() calls should be in the try block.