
Many times when using the heapq lib I had to convert my array to negative values so that it could behave like a max heap. Maybe we should pass in a parameter in the functions to specify if we want a max heap behaviour or a min heap behaviour.

I myself have proposed heap objects and seen that and other features come up from time to time. I think the general mood is to use a PyPI library, or even just vendor a single file from a package like xheap https://github.com/srkunze/xheap/blob/master/xheap.py If you wanted to stick with what's in the stdlib and have a minimal wrapper, you could turn your heap inputs into tuples of form `(key_function(object), object)`, and on getting them out, just get the object back. To have a max heap, key_function could just be operator.neg. On Wed, Apr 13, 2022 at 6:25 PM Eduardo Nery <eduardo.nery8@gmail.com> wrote:

I myself have proposed heap objects and seen that and other features come up from time to time. I think the general mood is to use a PyPI library, or even just vendor a single file from a package like xheap https://github.com/srkunze/xheap/blob/master/xheap.py If you wanted to stick with what's in the stdlib and have a minimal wrapper, you could turn your heap inputs into tuples of form `(key_function(object), object)`, and on getting them out, just get the object back. To have a max heap, key_function could just be operator.neg. On Wed, Apr 13, 2022 at 6:25 PM Eduardo Nery <eduardo.nery8@gmail.com> wrote:
participants (2)
-
Eduardo Nery
-
Nick Timkovich