daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Dec 11th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Deque:
  2.     'Fast searchable queue'
  3.     def __init__(self):
  4.         self.od = OrderedDict()
  5.     def appendleft(self, k):
  6.         od = self.od
  7.         if k in od:
  8.             del od[k]
  9.         od[k] = None
  10.     def pop(self):
  11.         return self.od.popitem(0)[0]
  12.     def remove(self, k):
  13.         del self.od[k]
  14.     def __len__(self):
  15.         return len(self.od)
  16.     def __contains__(self, k):
  17.         return k in self.od
  18.     def __iter__(self):
  19.         return reversed(self.od)
  20.     def __repr__(self):
  21.         return 'Deque(%r)' % (list(self),)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top