Complete the code to move to the last node in a singly linked list.
while current.next [1] None: current = current.next
The loop continues while current.next is not None, meaning current is not the last node.
Complete the code to update the second last node's next pointer to None, deleting the last node.
prev.next [1] None
We assign None to prev.next to remove the last node from the list.
Fix the error in the loop condition to find the second last node.
while current.next.next [1] None: current = current.next
The loop continues while current.next.next is not None, so current stops at second last node.
Fill both blanks to correctly handle deleting the last node when list has only one node.
if head.next [1] None: head [2] None
If head.next is None, it means only one node exists, so set head to None to delete it.
Fill all three blanks to complete the function that deletes the last node of a singly linked list.
def delete_last_node(head): if head is None: return None if head.next [1] None: return [2] current = head while current.next.next [3] None: current = current.next current.next = None return head
If head.next == None, list has one node, so return None after deleting it. Loop while current.next.next != None to reach second last node.