Complete the code to check if the linked list is empty before deletion.
if self.head is [1]: return
We check if self.head is None to see if the list is empty.
Complete the code to delete the head node if it contains the target value.
if self.head.data == [1]: self.head = self.head.next return
The variable target holds the value to delete.
Fix the error in the while loop condition to traverse the list correctly.
while current is not [1] and current.data != target: prev = current current = current.next
The loop should continue while current is not None, meaning nodes remain.
Fill both blanks to correctly remove the node by updating links.
if current is not None: [1].next = [2].next
We set prev.next to skip the current node, effectively deleting it.
Fill all three blanks to complete the delete_node method.
def delete_node(self, [1]): if self.head is None: return if self.head.data == [2]: self.head = self.head.next return prev = self.head current = self.head.next while current is not None and current.data != [3]: prev = current current = current.next if current is not None: prev.next = current.next
The method parameter is target, the value to delete. We compare self.head.data with target, and in the loop, we compare current.data with target.
