Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101375 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2016-01-08 14:26 +0100 |
| Last post | 2016-01-08 14:26 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to remove item from heap efficiently? Peter Otten <__peter__@web.de> - 2016-01-08 14:26 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-01-08 14:26 +0100 |
| Subject | Re: How to remove item from heap efficiently? |
| Message-ID | <mailman.68.1452259606.2305.python-list@python.org> |
Sven R. Kunze wrote: > Hi everybody, > > suppose, I need items sorted by two criteria (say timestamp and > priority). For that purpose, I use two heaps (heapq module): > > heapA # items sorted by timestamp > heapB # items sorted by priority > > Now my actual problem. When popping an item of heapA (that's the oldest > item), I need to remove the very same item from heapB, regardlessly > where it is in heapB. And vice versa. > > Is there a datastructure or a simple trick to achieve that in an > efficient matter? The heapq docs mention marking as deleted as an alternative to removing. Another option is to try sorted lists and bisect.
Back to top | Article view | comp.lang.python
csiph-web