bpo-37229: Add compare_function to bisect functions#13970
bpo-37229: Add compare_function to bisect functions#13970FortStatement wants to merge 1 commit intopython:masterfrom
Conversation
|
Please fix bpo number |
d2f526e to
056e27a
Compare
|
Hi @GPery, thanks for taking the time to improve Python! As @tirkarthi mentionned, #11781 is already open to add this functionnality thought. |
|
#11781 adds a key parameter, which I believe is inferior. It's a specific case of a comparison callback, and in my use case would force me to create another class to serve as a comparator for my objects, at which point I might as well wrap them and add lt. Furthermore, I believe this is more in-line with similar standard functions in other languages such as C++ (std::sort), Java (PriorityQueue) or Rust (slice.sort_by). |
|
|
|
@GPery, both are actually two ways to describe the same behavior, do you know |
|
You're right, both cases are about the same. |
|
I feel it might be relevant to note that this isn't reverting to the old-style (C-style) comparison. |
|
list sort uses |
|
"every compared pair" is also (up to) once per item. |
What's your point exactly? Even with custom keys, you still need to compare every compared pair with (Note: I do think that |
|
@jdemeyer IIRC at least for list sorting the point is that python-provided comparison function is usually much slower than built-in compare methods for |
OK, so the performance argument becomes "in certain use cases, using |
|
@asvetlov I'm not sure what were the original concerns, but I checked this PR and the I think this is a rather fair comparison. |
|
I just tried and had the opposite result, both with and without pydebug, I wonder what exactly might be doing that. |
|
Hi there, why was this one closed? Was it superseded/WONTFIXED? This addition would be amazing, I keep hitting it. Let me know if there's any way I can help. Thanks to all. |
All of bisect's functions (insort_{left,right}, bisect_{left,right}) can only use comparison of objects via
__lt__.They should support providing a custom comparison function.
https://bugs.python.org/issue37229