Complete the code to define a node in a doubly linked list with pointers to both previous and next nodes.
class Node: def __init__(self, data): self.data = data self.prev = [1] self.next = None
In a doubly linked list, the previous pointer of a new node is initially set to None because it does not point to any node yet.
Complete the code to insert a new node at the beginning of a doubly linked list.
def insert_at_head(head, data): new_node = Node(data) new_node.next = head if head is not None: head.[1] = new_node return new_node
When inserting at the head, the previous pointer of the old head node should point back to the new node.
Fix the error in the code that deletes a node from a doubly linked list.
def delete_node(node): if node.prev is not None: node.prev.next = node.next if node.next is not None: node.next.[1] = node.prev
When deleting a node, the next node's previous pointer must be updated to skip the deleted node.
Fill both blanks to create a dictionary comprehension that maps node data to their next node's data if the next node exists.
{node.data: node.next[1] for node in nodes if node.next is not [2]The comprehension accesses the data of the next node and filters out nodes where next is None.
Fill all three blanks to create a dictionary comprehension that maps uppercase node data to the previous node's data if the previous node exists and its data is greater than 10.
{node.data[1]: node.prev[2] for node in nodes if node.prev is not None and node.prev.data [3] 10}The comprehension converts node data to uppercase, accesses the previous node's data, and filters nodes where previous data is greater than 10.