World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Implementation of Deque :
Methods and Attributes
Deque Implementation :
class Deque: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def addFront(self, item): self.items.append(item) def addRear(self, item): self.items.insert(0,item) def removeFront(self): return self.items.pop() def removeRear(self): return self.items.pop(0) def size(self): return len(self.items) def print(self): return self.items d = Deque() d.addFront('hello') d.addRear('world') d.print() # output ['world', 'hello'] d.size() # output 2 print (d.removeFront() + ' ' + d.removeRear()) # output hello world d.size() # output 0