<div id=":63" class="ii gt"><span class="il">blist</span> 1.1.1 is now available:<br><br> <a href="http://pypi.python.org/pypi/blist/" target="_blank">http://pypi.python.org/pypi/<span class="il">blist</span>/</a><br>
<br>What is <span class="il">blist</span>?<br>--------------<br><br>The blist is a drop-in replacement for the Python list the provides<br>better performance when modifying large lists. Python's built-in list<br>is a dynamically-sized array; to insert or removal an item from the<br>
beginning or middle of the list, it has to move most of the list in<br>memory, i.e., O(n) operations. The blist uses a flexible, hybrid<br>array/tree structure and only needs to move a small portion of items<br>in memory, specifically using O(log n) operations.<br>
<br>For small lists, the blist and the built-in list have virtually<br>identical performance.<br><br>What's new?<br>-----------<br><br><span class="il">blist 1.1 introduces other data structures based on the blist:<br>
<br>- sortedlist<br>- sortedset<br>- weaksortedlist<br>- weaksorteset<br>- sorteddict<br>- btuple<br><br>These additional data structures are only available in Python 2.6 or<br>higher, as they make use of Abstract Base Classes.<br>
<br>The sortedlist is a list that's always sorted. It's iterable and<br>indexable like a Python list, but to modify a sortedlist the same<br>methods you would use on a Python set (add, discard, or remove).<br><br>
>>> from blist import sortedlist<br>>>> my_list = sortedlist([3,7,2,1])<br>>>> my_list<br>sortedlist([1, 2, 3, 7])<br>>>> my_list.add(5)<br>>>> my_list[3]<br>5<br>>>><br>
<br>The sortedlist constructor takes an optional "key" argument, which may<br>be used to change the sort order just like the sorted() function.<br><br>>>> from blist import sortedlist<br>>>> my_list = sortedlist([3,7,2,1], key=lambda i: -i)<br>
sortedlist([7, 3, 2, 1]<br>>>><br><br>The sortedset is a set that's always sorted. It's iterable and<br>indexable like a Python list, but modified like a set. Essentially,<br>it's just like a sortedlist except that duplicates are ignored.<br>
<br>>>> from blist import sortedset<br>>>> my_set = sortedset([3,7,2,2])<br>sortedset([2, 3, 7]<br>>>><br><br>The weaksortedlist and weaksortedset are weakref variations of the<br>sortedlist and sortedset.<br>
<br>The sorteddict works just like a regular dict, except the keys are<br>always sorted. The sorteddict should not be confused with Python<br>2.7's OrderedDict type, which remembers the insertion order of the<br>keys.<br>
<br>>>> from blist import sorteddict<br>>>> my_dict = sorteddict({1: 5, 6: 8, -5: 9})<br>>>> my_dict.keys()<br>[-5, 1, 6]<br>>>><br><br>The btuple is a drop-in replacement for the built-in tuple. Compared<br>
to the built-in tuple, the btuple offers the following advantages:<br><br>- Constructing a btuple from a blist takes O(1) time.<br>- Taking a slice of a btuple takes O(n) time, where n is the size of<br> the original tuple. The size of the slice does not matter.<br>
<br>>>> from blist import blist, btuple<br>>>> x = blist([0]) # x is a blist with one element<br>>>> x *= 2**29 # x is a blist with > 500 million elements<br>>>> y = btuple(x) # y is a btuple with > 500 million elements</span><br>
<br>Feedback<br>--------<br><br>We're eager to hear about your experiences with the blist. You can<br>email me at <a href="mailto:daniel@stutzbachenterprises.com">daniel@stutzbachenterprises.com</a>. Alternately, bug reports<br>
and feature requests may be reported on our bug tracker at:<br><a href="http://github.com/DanielStutzbach/blist/issues">http://github.com/DanielStutzbach/blist/issues</a><br><blockquote style="margin: 1.5em 0pt;">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com/" target="_blank">Stutzbach Enterprises, LLC</a>
</blockquote>
</div>