title: Implementing an efficient queue in Python
body: <p>I have been trying to implement a queue in Python, and I've been running into a problem.</p>
  <p>I am attempting to use lists to implement the Queue data structure, however I can't quite figure out how to make <code>enqueue</code> and <code>dequeue</code> O(1) operations.</p>
  <p>Every example I have seen online, seems to just append the <code>enqueue</code> operation and remove the first element from the list for the <code>dequeue</code> operation. But this would make the <code>dequeue</code> operation O(n) (where n is the size of the list) correct?</p>
  <p>Is there something basic I have missed? Or do you have to use LinkedLists to implement a Queue efficiently?</p>
  <pre><code>import unittest
  
  class Queue:
      def __init__(self):
          self._queue = []
          self.size = 0
          self.maxSize = 10
  
      def enqueue(self, item):
          if self.size &lt; self.maxSize:
              self._queue.append(item)
  
      def dequeue(self):
          '''
          Removes an item from the front of the list. Remove first element of
          the array
          '''
          first = self._queue[0]
          del self._queue[0]
          return first
  </code></pre>