title: How can I make a unique value priority queue in Python?
body: <p>Python has Queue.PriorityQueue, but I cannot see a way to make each value in it unique as there is no method for checking if a value already exists (like find(name) or similar). Moreover, PriorityQueue needs the priority to remain within the value, so I could not even search for my value, as I would also have to know the priority. You would use (0.5, myvalue) as value in PriorityQueue and then it would be sorted by the first element of the tuple.</p>
  
  <p>The collections.deque class on the other hand does offer a function for checking if a value already exists and is even more natural in usage (without locking, but still atomic), but it does not offer a way to sort by priority.</p>
  
  <p>There are some other implementations on stackoverflow with heapq, but heapq also uses priority within the value (e.g. at the first position of a tuple), so it seems not be great for comparison of already existing values.</p>
  
  <p><a href="https://stackoverflow.com/questions/3311480/creating-a-python-priority-queue">Creating a python priority Queue</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3306179/priority-queue-problem-in-python">https://stackoverflow.com/questions/3306179/priority-queue-problem-in-python</a></p>
  
  <p>What is the best way of creating a atomic priority queue (=can be used from multiple threads) with unique values?</p>
  
  <p>Example what I’d like to add:</p>
  
  <ul>
  <li>Priority: 0.2, Value: value1</li>
  <li>Priority: 0.3, Value: value2</li>
  <li>Priority: 0.1, Value: value3 (shall be retrieved first automatically)</li>
  <li>Priority: 0.4, Value: value1 (shall not be added again, even though it has different priority)</li>
  </ul>