Next / Previous / Contents / Shipman's homepage

4.27. SkipList.__delitem__()

The .__delitem__() method is another special method that is called when the user applies the Python del statement to one element of a skip list. It's really the same thing as the .delete() method, except the caller doesn't want the deleted item.

In the case where there are multiple children with the same key, it's not obvious whether a user would expect to delete all of them. We arbitrary say it will delete only one. If one wishes to delete them all, one can always write a loop that calls .delete() until it returns a None to signify that no elements were deleted.
# - - -   S k i p L i s t . _ _ d e l i t e m _ _   - - -

    def __delitem__ ( self, key ):
        """Delete the first or only item with a given key."""
        self.delete ( key )