non-copy slices

Daniel Stutzbach daniel at
Thu Nov 19 03:47:07 CET 2009

On Wed, Nov 18, 2009 at 2:22 PM, Themis Bourdenas <
t.bourdenas07 at> wrote:

> It's nothing in the library that completely imitates the slice without the
> copies, right?

You might be interested in my blist extension type (link below).
Syntactically, using a blist is just like using a list, but it has different
performance characteristics.

In particular for your needs, taking a slice is cheap.  The blist implements
copy-on-write behind the scenes, so taking a slice takes O(log n) time,
where n is the size of the initial blist.

Here is a simple example, which creates a blist with over 500 million
elements and takes a slice of over 500 million elements.  In under 22
microseconds. :-)

from blist import blist
small_list = blist([0])
BIG_list = small_list * 2**29
BIG_slice = BIG_list[4:-5]

Cashew:~$ python2.5 -m timeit -s 'from blist import blist'
'small_list=blist([0])' ''BIG_list=small_list*2**29'
10000 loops, best of 3: 21.5 usec per loop

Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list