{"record":{"id":"d9ad76b68da6db75","repo":"TheAlgorithms/Python","slug":"no-data-matching-given-value","errorCode":null,"errorMessage":"No data matching given value","messagePattern":"No data matching given value","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"data_structures/linked_list/doubly_linked_list.py","lineNumber":166,"sourceCode":"            self.tail = self.tail.previous\n            self.tail.next = None\n        else:\n            temp = self.head\n            for _ in range(index):\n                temp = temp.next\n            delete_node = temp\n            temp.next.previous = temp.previous\n            temp.previous.next = temp.next\n        return delete_node.data\n\n    def delete(self, data) -> str:\n        current = self.head\n\n        while current.data != data:  # Find the position to delete\n            if current.next:\n                current = current.next\n            else:  # We have reached the end an no value matches\n                raise ValueError(\"No data matching given value\")\n\n        if current == self.head:\n            self.delete_head()\n\n        elif current == self.tail:\n            self.delete_tail()\n\n        else:  # Before: 1 <--> 2(current) <--> 3\n            current.previous.next = current.next  # 1 --> 3\n            current.next.previous = current.previous  # 1 <--> 3\n        return data\n\n    def is_empty(self):\n        \"\"\"\n        >>> linked_list = DoublyLinkedList()\n        >>> linked_list.is_empty()\n        True\n        >>> linked_list.insert_at_tail(1)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/linked_list/doubly_linked_list.py#L148-L184","documentation":"DoublyLinkedList.delete(data) walks the chain and raises ValueError('No data matching given value') when it reaches the last node without finding an equal datum. This is a value-lookup failure, distinct from the positional IndexErrors the same class uses.","triggerScenarios":"delete(x) where x is not equal (==) to any node's data; calling delete on an empty list (current starts at head=None, so it dereferences immediately); searching for a value whose type differs, e.g. delete('1') in a list of ints.","commonSituations":"Deduplication or removal driven by user input without prior membership check; type mismatches between stored and searched values (str vs int from JSON); deleting an item already removed by a concurrent iteration.","solutions":["Catch ValueError specifically around delete-by-value calls and treat as 'not present'.","Pre-check membership if the class offers __contains__, or compare types before calling.","For empty-list safety, guard with len(linked_list) > 0 first."],"exampleFix":"# before\nlinked_list.delete(user_value)  # ValueError if absent\n# after\ntry:\n    linked_list.delete(user_value)\nexcept ValueError:\n    pass  # value not present; nothing to remove","handlingStrategy":"try-catch","validationCode":"# no built-in contains; manual pre-check\nfound = any(node == target for node in iter_over(dll)) if dll.head else False","typeGuard":null,"tryCatchPattern":"try:\n    dll.delete(value)\nexcept ValueError:\n    pass  # value not present — treat as idempotent no-op","preventionTips":["Normalize types (e.g. str vs int) before value-based deletes.","Catch ValueError, the type this method uses for lookup failure.","Guard the empty list case before calling delete."],"tags":["linked-list","value-error","delete","membership"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}