Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

queue.py

By: petew71 on Aug 3rd, 2013  |  syntax: Python  |  size: 0.63 KB  |  views: 30  |  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 Queue(object):
  2.     def __init__(self):
  3.         """ Initialise empty Queue list."""
  4.         self.li = []
  5.        
  6.     def insert(self,item):
  7.         """ Add item to back of Queue."""
  8.         self.li.append(item)
  9.        
  10.     def remove(self):
  11.         """ Check if items in the Queue list.
  12.            If True, remove the first item.
  13.            Else, return 'empty queue.'"""
  14.         if self.li:
  15.             return self.li.pop(0)
  16.         return 'empty queue'
  17.    
  18. queue = Queue()
  19. queue.insert(5)
  20. queue.insert(6)
  21. print queue.remove()
  22. queue.insert(7)
  23. print queue.remove()
  24. print queue.remove()
  25. print queue.remove()