from collections import deque # create a linked list using deque linked_list = deque([1, 2, 3]) # add an element linked_list.append(4) # remove an element linked_list.pop() # print the linked list print(linked_list)
deque([1, 2, 3])
from collections import namedtuple # create a node object with data and a reference to the next node Node = namedtuple('Node', ['data', 'next']) # create a linked list using nodes head = Node(1, None) node2 = Node(2, None) node3 = Node(3, None) head.next = node2 node2.next = node3 # print the linked list current_node = head while current_node: print(current_node.data) current_node = current_node.next
1 2 3