<div class="gmail_quote">On Thu, Feb 9, 2012 at 12:34 PM, Raymond Hettinger <span dir="ltr"><<a href="mailto:raymond.hettinger@gmail.com">raymond.hettinger@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word"><div>Bisect in particular had way too much focus on the algorithm.  The API is awkward and error-prone for many common use cases.</div><div><br></div><div>I've tried to remedy that through documenting how to implement the common use cases:   <a href="http://docs.python.org/py3k/library/bisect.html#searching-sorted-lists" target="_blank">http://docs.python.org/py3k/library/bisect.html#searching-sorted-lists</a></div>

<div><br></div><div>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.</div>

<div><br></div><div>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.  </div><div><br></div><div>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.</div>

<span class="HOEnZb"></span></div></blockquote></div><br>Maybe you're overanalyzing the problem? It seems what you want would require a PEP and/or a reference implementation that is thoroughly tested as a 3rd party package before it warrants inclusion into the stdlib. In the mean time adding a key= option that echoes the API offered by list.sort() and sorted() is a no-brainer.<br clear="all">

<br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>