title: How to deal with items with the same priority in a priority queue? (Python)
body: <p>I am trying to create a priority queue, which processes input in this form:</p>
  
  <pre><code>enqueue 2 2
  enqueue 1 3
  enqueue 5 1
  enqueue 6 2
  dequeue
  dequeue
  dequeue
  dequeue
  </code></pre>
  
  <p>I have this code that uses lists:</p>
  
  <pre><code>from queue import Queue
  data=[]
  while True: 
      try:
          operation = input()
      except:
          break
      data.append(operation.split(" "))
  
  data2=[] 
  data3=[]
  for i in data: #split enqueue and dequeue as not to get an out of range error
      if "enqueue" in i:
          data2.append(i)
      else:
          data3.append(i)
  
  data2=sorted(data2,key=lambda x: int(x[2]))
  data2=data2[::-1]
  
  data=data2+data3 #merged the two again after sorting
  
  q=[]
  
  for i in data:
      if "enqueue" in i: #add the item by the already sorted order of priority
          q.append(i[1])
      if "dequeue" in i: #print the first item dequeued before removing it from the queue
          print (q[0])
          del q[0]
  </code></pre>
  
  <p>My problem with this is that it outputs:</p>
  
  <pre><code>1
  6
  2
  5
  </code></pre>
  
  <p>Instead of: (since 2 was technically enqueued before 6, and in the case of items having the same priority, they need to follow the FIFO structure of queues)</p>
  
  <pre><code>1
  2
  6
  5
  </code></pre>
  
  <p>Does anyone have any idea on how I can fix this? Is there an alternate way to solve this using queues instead of lists? Thanks!</p>