擅长:python、mysql、java
<p>如果您确实需要从<code>heap</code>中取出一个项,但希望保留<code>heap</code>,则可以懒洋洋地执行该操作,并在该项自然出现时将其丢弃,而不是在列表中搜索该项。</p>
<p>如果您将要删除的项目存储在黑名单<code>set</code>中,那么每次您<code>heapq.heappop</code>检查该项目是否在<code>set</code>中。如果它存在,则丢弃它并再次<code>heappop</code>,直到得到未列入黑名单的内容,或者<code>heap</code>为空</p>