Complete the code to initialize the previous pointer to None.
def reverse_linked_list(head): prev = [1] current = head while current: next_node = current.next current.next = prev prev = current current = next_node return prev
We start with prev as None because the new tail of the reversed list points to nothing.
Complete the code to save the next node before changing the current node's next pointer.
def reverse_linked_list(head): prev = None current = head while current: [1] = current.next current.next = prev prev = current current = next_node return prev
We save the next node in next_node before changing links to avoid losing the rest of the list.
Fix the error in updating the current pointer to the next node.
def reverse_linked_list(head): prev = None current = head while current: next_node = current.next current.next = prev prev = current current = [1] return prev
After reversing the link, we move current to the saved next_node to continue traversal.
Fill both blanks to complete the loop condition and return statement correctly.
def reverse_linked_list(head): prev = None current = head while [1]: next_node = current.next current.next = prev prev = current current = next_node return [2]
The loop runs while current is not None, and we return prev which is the new head of the reversed list.
Fill all three blanks to create a dictionary comprehension that maps node values to their reversed positions.
def map_reversed_positions(head): reversed_list = reverse_linked_list(head) position_map = { [1]: index for index, node in enumerate(iter_nodes(reversed_list)) if node.value [2] 0 and node.value [3] 100 } return position_map
The dictionary maps each node's value to its index if the value is greater than 0 and less than 100.