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

Raymond Hettinger raymond.hettinger at gmail.com
Thu Feb 9 18:27:25 CET 2012

On Feb 8, 2012, at 4:25 PM, Guido van Rossum wrote:

> Also note that "many times" is actually O(log N) per insertion, which isn't so bad. The main use case for bisect() is to manage a list that sees updates *and* iterations -- otherwise building the list unsorted and sorting it at the end would make more sense. The key= option provides a balance between the cost/elegance for updates and for iterations.

Would you be open to introducing a SortedList class to encapsulate the data so that key functions get applied no more than once per record and the sort order is maintained as new items are inserted?

ISTM, the whole problem with bisect is that the underlying list is naked, leaving no way to easily correlate the sort keys with the corresponding sorted records.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120209/203d9849/attachment.html>

More information about the Python-ideas mailing list