<jupyter_start><jupyter_text>A **deque**, also known as a **double-ended queue**, is an ordered collection of items similar to the queue. It has two ends, a front and a rear, and the items remain positioned in the collection. What makes a deque different is the unrestrictive nature of adding and removing items. New items can be added at either the front or the rear. Likewise, existing items can be removed from either end. In a sense, this hybrid linear structure provides all the capabilities of stacks and queues in a single data structure. Figure 1: A Deque of Python Data Objects The deque operations are given below.1.   `Deque()` creates a new deque that is empty. It needs no parameters and returns an empty deque.2.    `add_front(item)` adds a new item to the front of the deque. It needs the item and returns nothing.3.    `add_rear(item)` adds a new item to the rear of the deque. It needs the item and returns nothing.4.    `remove_front()` removes the front item from the deque. It needs no parameters and returns the item. The deque is modified.5.    `remove_rear()` removes the rear item from the deque. It needs no parameters and returns the item. The deque is modified.6.    `is_empty()` tests to see whether the deque is empty. It needs no parameters and returns a boolean value.7.    `len()` returns the number of items in the deque. It needs no parameters and returns an integer.<jupyter_code>class Deque:

    def __init__(self, items=[]):
        self.items = items

    def is_empty(self):
        return self.items == []

    def add_front(self, item):
        self.items.append(item)

    def add_rear(self, item):
        self.items.insert(0,item)

    def remove_front(self):
        return self.items.pop()

    def remove_rear(self):
        return self.items.pop(0)

    def __len__(self):
        return len(self.items)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07385759829968119, 'fraction_numerical': 0.005313496280552604, 'mean_word_length': 3.5047846889952154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '293070', 'license': 'MIT', 'n_tokens_mistral': 534, 'n_tokens_neox': 511, 'n_words': 262, 'path': 'Dequeue.ipynb', 'repo_name': 'Yasir323/Data-Structures-and-Algorithms-in-Python', 'size': '1882'}