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

Raymond Hettinger raymond.hettinger at gmail.com
Thu Feb 9 21:34:47 CET 2012

On Feb 9, 2012, at 9:48 AM, Guido van Rossum wrote:

> The more fundamental "conflict" here seems to be between algorithms and classes. list.sort(), bisect and heapq focus on the algorithm.

Bisect in particular had way too much focus on the algorithm.  The API is awkward and error-prone for many common use cases.

I've tried to remedy that through documenting how to implement the common use cases:   http://docs.python.org/py3k/library/bisect.html#searching-sorted-lists

The issue is that the current API focuses on "insertion points" rather than on finding values.  Unfortunately, this API is very old, so the only way to fix it is to introduce a new class.

If we introduced class around a sorted sequence, then we could make an reasonable API that corresponds to what people usually want to do with sorted sequences.  

Of course, that still leaves the issue with an O(n) insort.  As Daniel pointed-out, a list is not the correct underlying data structure if you want to do periodic insertions and deletions.


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

More information about the Python-ideas mailing list