Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Python deque implementation

By: a guest on Sep 21st, 2011  |  syntax: Python  |  size: 0.46 KB  |  hits: 62  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class deque:
  2.         def __init__(self):
  3.                 self._data = []
  4.  
  5.         def add_front(self, i):
  6.                 self._data.insert(0, i)
  7.  
  8.         def add_back(self, i):
  9.                 self._data.append(i)
  10.  
  11.         def remove_front(self):
  12.                 return self._data.pop(0)
  13.  
  14.         def remove_back(self):
  15.                 return self._data.pop()
  16.  
  17.         def front(self):
  18.                 return self._data[0]
  19.  
  20.         def back(self):
  21.                 return self._data[-1]
  22.  
  23.         def is_empty(self):
  24.                 return len(self._data) == 0
  25.  
  26.         def __str__(self):
  27.                 return self._data.__str__()