Python offers many useful characteristics in its standard libraries. Hidden in the collections Library, there is a less known data structure, the and (1) (Apparently pronounced deck). Let me show you what it is, how it works and why it is a perfect data structure to draw continuous data of a flow!
AND It is a type of data imported from the collections module, it means a double -end tail. Essentially it is a list with two ends, so you can easily add/remove from the head or tail.
To use it, we declare a variable for the tail. Since the tail has two ends, we can easily add both ends with anyone add To add to the tail or appendix To add to the beginning of the list.
from collections import dequemy_queue = deque()
my_queue.append("a")
my_queue.append("b")
my_queue.appendleft("c")
my_queue.appendleft("d")
print(my_queue) # deque(('d', 'c', 'a', 'b'))
You can also appear from both ends of the tail with pop For the right side or pallette to eliminate elements from the beginning.
my_queue.pop()
print(my_queue) # deque(('d', 'c', 'a'))my_queue.popleft()
print(my_queue) # deque(('c', 'a'))