title: What is the code doing in a Python queue "peek"?
body: <p>This python code below uses a queue system with two stacks. From what I understand, during the "peek" function--we are looking at the top of the list and returning it.</p>
  
  <pre><code>def peek(self):
      #looks at the top of the queue
      if len(self.stack2) &gt; 0:
          top = self.stack2.pop() 
          self.stack2.append(top)
      else:
          #takes items in stack 1 and put into stack 2
          while len(self.stack1) &gt; 1:
              self.stack2.append(self.stack1.pop())
          top = self.stack1.pop() 
          self.stack2.append(top) 
      return top
  </code></pre>
  
  <p>As you can see in the first if statement condition, it does a <code>self.stack2.pop()</code> and appends it to <code>top</code>. However the <code>.pop()</code> method is supposed to remove the item at the end of the list. Why is it being assigned to <code>top</code>? Shouldn't we use <code>self.stack2.pop(0)</code> which would remove the first item in the queue?</p>