[Python-ideas] Optional key to `bisect`'s functions?

Amaury Forgeot d'Arc amauryfa at gmail.com
Wed Feb 8 23:18:54 CET 2012


Hi,

2012/2/8 Masklinn <masklinn at masklinn.net>

> The ``bisect`` stuff is pretty neat, although probably underused
> (especially the insorts), but their usefulness is limited by the
> requirement that the lists directly contain sortable items, as opposed
> to ``sorted`` or ``list.sort``.
>
> It's possible to "use" them by copy/pasting the (Python) functions
> into the project/library code and adding either a custom key directly
> or a key function, but while this can still yield an
> order-of-magnitude speed gain over post-sorting sequences, it's
> cumbersome and it loses the advantage of _bisect's accelerators.
>
> Therefore, I believe it would be pretty neat to add an optional
> ``key=`` keyword (only?) argument, with the same semantics as in
> ``sorted``. It would make ``bisect`` much easier to use especially
> in stead of append + sorted combinations. The key should work for
> both insertion functions and bisection search ones.
> bisect key


This was proposed several times on the issue tracker (search for "bisect
key"),
and these proposals have always been rejected:
http://bugs.python.org/issue4356
http://bugs.python.org/issue1451588
http://bugs.python.org/issue3374
The last one summarizes the reasons of the rejection.
The documentation (http://docs.python.org/library/bisect.html, "see also")
contains a link to a "SortedCollection" recipe.

I haven't looked at the SortedCollection class in detail, but you could try
to have it included in the stdlib...

-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120208/510a247e/attachment.html>


More information about the Python-ideas mailing list