[Python-ideas] A key parameter for heapq.merge

Simon Sapin simon.sapin at kozea.fr
Sun Jan 8 22:58:05 CET 2012


According to its own documentation, the merge() function in the heapq 
module is similar to sorted(). However, it has none of the key and 
reverse parameters that sorted() has. I think they could be just as 
useful as in sorted().


First of all what do you think of the idea?

I’m working on a patch for a key parameter. I think it can be pretty 
straightforward, but I’ll measure if the "no key" case becomes slower 
(calls to lambda x: x) At worst we can always duplicate the loop.

However, I am not sure how to implement reverse. Not all values have an 
"opposite value" that reverses order, _nsmallest and _nlargest are quite 
different, and merge uses neither.

Anyway, if I get this to work, it will be my first contribution to 
CPython. I’m trying to follow the Developer’s guide, but is there 
something else I should be aware of?


Simon Sapin

More information about the Python-ideas mailing list