list is a very fast and efficient
sequence type, but it could be better for certain access patterns,
such as non-sequential insertion into a large lists.
provides a pure-Python solution to this problem.
For utilities for working with iterables and lists, check out
iterutils. For the a
list-based version of
collections.namedtuple, check out
listsubtype backed by many dynamically-scaled sublists, to provide better scaling and random insertion/deletion characteristics. It is a subtype of the builtin
listand has an identical API, supporting indexing, slicing, sorting, etc. If application requirements call for something more performant, consider the blist module available on PyPI.
The name comes by way of Kurt Rose, who said it reminded him of barrel shifters. Not sure how, but it’s BList-like, so the name stuck. BList is of course a reference to B-trees.
Parameters: iterable – An optional iterable of initial values for the list.
>>> blist = BList(xrange(100000)) >>> blist.pop(50000) 50000 >>> len(blist) 99999 >>> len(blist.lists) # how many underlying lists 8 >>> slice_idx = blist.lists[-1] >>> blist[slice_idx:slice_idx + 2] BarrelList([11637, 11638])
Slicing is supported and works just fine across list borders, returning another instance of the BarrelList.
del_slice(start, stop, step=None)¶
iter_slice(start, stop, step=None)¶