Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're looking for an implementation of an efficient container type for Python implemented using something like a balanced search tree (A Red-Black tree for example) then it's not part of the standard library.</p> <p>I was able to find this, though:</p> <p><a href="http://www.brpreiss.com/books/opus7/" rel="nofollow noreferrer">http://www.brpreiss.com/books/opus7/</a></p> <p>The source code is available here:</p> <p><a href="http://www.brpreiss.com/books/opus7/public/Opus7-1.0.tar.gz" rel="nofollow noreferrer">http://www.brpreiss.com/books/opus7/public/Opus7-1.0.tar.gz</a></p> <p>I don't know how the source code is licensed, and I haven't used it myself, but it would be a good place to start looking if you're not interested in rolling your own container classes.</p> <p>There's <a href="http://linux.softpedia.com/get/Programming/Libraries/pyavl-43893.shtml" rel="nofollow noreferrer">PyAVL</a> which is a C module implementing an AVL tree.</p> <p>Also, <a href="http://mail.python.org/pipermail/python-list/2007-September/628938.html" rel="nofollow noreferrer">this thread</a> might be useful to you. It contains a lot of suggestions on how to use the bisect module to enhance the existing Python dictionary to do what you're asking.</p> <p>Of course, using insort() that way would be pretty expensive for insertion and deletion, so consider it carefully for your application. Implementing an appropriate data structure would probably be a better approach.</p> <p>In any case, to understand whether you should keep the data structure sorted or sort it when you iterate over it you'll have to know whether you intend to insert a lot or iterate a lot. Keeping the data structure sorted makes sense if you modify its content relatively infrequently but iterate over it a lot. Conversely, if you insert and delete members all the time but iterate over the collection relatively infrequently, sorting the collection of keys before iterating will be faster. There is no one correct approach. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload