<s>[INST] class DoublyLinkedNode:
    def __init__(self, val=0, prev=None, next=None):
        self.val = val
        self.prev = prev
        self.next = next

class DoublyLinkedList:
    def __init__(self):
        self.head = DoublyLinkedNode()
        self.tail = DoublyLinkedNode(prev=self.head)

        self.head.next = self.tail

    def prepend(self, val):
        new_node = DoublyLinkedNode(val=val, next=self.head.next, prev=self.head)
        self.head.next.prev = new_node
        self.head.next = new_node

    def append(self, val):
        new_node = DoublyLinkedNode(val=val, prev=self.tail.prev, next=self.tail)
        self.tail.prev.next = new_node
        self.tail.prev = new_node

    def print_list(self):
        node = self.head.next
        while node != self.tail:
            print(node.val, end=' ')
            node = node.next
        print()

doubly_linked_list = DoublyLinkedList()
doubly_linked_list.prepend(1)
doubly_linked_list.prepend(2)
doubly_linked_list.append(3)
doubly_linked_list.append(4)

doubly_linked_list.print_list()[/INST]