class Node: def __init__(self, data=None, next_node=None): self.data = data self.next = next_node class LinkedList: def __init__(self): self.head = None def add_to_list(self, data): if not self.head: self.head = Node(data=data) else: current = self.head while current.next: current = current.next current.next = Node(data=data)
my_list = LinkedList() my_list.add_to_list(1) my_list.add_to_list(2) my_list.add_to_list(3)
from collections import deque my_deque = deque([1, 2, 3]) my_deque.append(4)In this example, we create a `deque` object containing the numbers 1, 2, and 3. We then call the `append()` method to add the number 4 to the end of the list.