[Python-ideas] A key parameter for heapq.merge (original) (raw)
Simon Sapin simon.sapin at kozea.fr
Sun Jan 8 22:58:05 CET 2012
- Previous message: [Python-ideas] adding a casefold() method to str
- Next message: [Python-ideas] A key parameter for heapq.merge
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
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().
http://docs.python.org/dev/library/heapq.html#heapq.merge http://docs.python.org/dev/library/functions.html#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?
http://docs.python.org/devguide/
Regards,
Simon Sapin
- Previous message: [Python-ideas] adding a casefold() method to str
- Next message: [Python-ideas] A key parameter for heapq.merge
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]