Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created March 21, 2021 18:43
Show Gist options
  • Save Clivern/765b3d4dc59dc8cab8d29bd5e0177c66 to your computer and use it in GitHub Desktop.
Save Clivern/765b3d4dc59dc8cab8d29bd5e0177c66 to your computer and use it in GitHub Desktop.
Python Deque
class Deque():
"""Deque DST"""
def __init__(self):
self._items = []
def add_front(self, item):
"""
Add to the front
"""
self._items.append(item)
def add_rear(self, item):
"""
Add to the back
"""
self._items.insert(0, item)
def remove_front(self):
"""
Remove from the front
"""
return self._items.pop()
def remove_rear(self):
"""
Remove from the back
"""
return self._items.pop(0)
def size(self):
"""
Get the size
"""
return len(self._items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment