title: Remove element from heapq
body: <p>I am trying to implement the AStar search algorithm and I'm having trouble removing elements from the fringe (open list). I push my <code>Cells</code> in like this:</p>
  
  <pre><code>heapq.heappush(myHeap, (priority, cell)
  </code></pre>
  
  <p>My cell class looks like this:</p>
  
  <pre><code>class Cell(object):
      def __init__(self, x, y):
          self.X = int(x)
          self.Y = int(y)
          self.G = float("inf")
          self.parent = None
  
      def __lt__(self, other):
          return (self.X, self.Y) &lt; (other.X, other.Y)
  
      def __eq__(self, other):
          return int(self.X) == int(other.X) and int(self.Y) == int(other.Y)
  </code></pre>
  
  <p>Is there a way I can just do <code>heapq.remove(cell)</code> or <code>heapq.heappop(cell)</code> to remove the entry from the heap and then reheapify it? </p>
  
  <p>Currently, I'm doing it like this but I don't think it's working correctly as I get an infinite loop sometimes:</p>
  
  <pre><code>def remove(self, item):
      index = 0
  
      for i in range(len(myHeap)):
          if(myHeap[i][1] == item):
              index = i
  
      # Move slot to be removed to top of heap
      while index &gt; 0:
          up = int((index + 1) / 2 - 1)
          self.heap[index] = self.heap[up]
          index = up
  
      # Remove top of heap and restore heap property
      heapq.heappop(myHeap)
  </code></pre>
  
  <p>Any help would be appreciated.</p>