Чтобы реализовать дек (двустороннюю очередь) с использованием массива в Python, вы можете использовать модуль collections, который предоставляет класс deque. Вот пример:
from collections import deque
# Create an empty deque
my_deque = deque()
# Add elements to the deque
my_deque.append(1) # Adds 1 to the right end of the deque
my_deque.appendleft(2) # Adds 2 to the left end of the deque
# Access elements in the deque
print(my_deque[0]) # Prints the leftmost element (2)
print(my_deque[-1]) # Prints the rightmost element (1)
# Remove elements from the deque
my_deque.pop() # Removes and returns the rightmost element (1)
my_deque.popleft() # Removes and returns the leftmost element (2)
# Check if the deque is empty
print(len(my_deque) == 0) # True
# Convert deque to a list
my_list = list(my_deque)
print(my_list) # Prints an empty list ([])
В приведенном выше примере используется класс dequeиз модуля collections. Метод append()добавляет элемент в правый конец двухсторонней очереди, а метод appendleft()добавляет элемент в левый конец. Метод pop()удаляет и возвращает самый правый элемент, а метод popleft()удаляет и возвращает самый левый элемент. Длину дека можно проверить с помощью len(), а дек можно преобразовать в список с помощью list().