I need a data structure like a dict where I can insert elements with a key and then efficiently take out largest element by value when I need it.
Asked
Active
Viewed 35 times
0
-
2@Firelord I mean, that's just using `heapq` – juanpa.arrivillaga Aug 11 '22 at 17:00
-
In any case, the linked dupicate is for a *sorted list*, which isn't precisely what you are asking, but is that what you are looking for? Otherwise, use a heap. EDIT: I added a duplicate target for a max heap using the `heapq` module in the standard library – juanpa.arrivillaga Aug 11 '22 at 17:00
-
`heapq` is smallest-first, but you can insert tuples like `(-key, item)` – tobias_k Aug 11 '22 at 17:01