Re: Efficient way to break up a list into two pieces

2010-02-21 Thread marwie
On 21 Feb., 07:38, Carl Banks wrote: > Numpy arrays can share underlying data like that when you take > slices.  For instance, this probably works the way you want: > > a = numpy.array([1,2,3,4,5,6]) > b = a[:3] > c = a[3:] > > None of the actual data was copied here. Hmm, that might be worth loo

Re: Efficient way to break up a list into two pieces

2010-02-21 Thread marwie
On 21 Feb., 04:40, Steven D'Aprano wrote: > > Additionally, Python lists are over-allocated so that appends are fast. A > list of (say) 1000 items might be over-allocated to (say) 1024 items, so > that you can do 24 appends before the array is full and the array needs > to be resized. This means t

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
On 21 Feb., 02:41, Steven D'Aprano wrote: > What the OP is doing is quite different: > > (1) copy l1[:10] > (2) assign the name l2 to it > (3) resize l1 in place to the first 10 items. > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the f

Re: Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
On 21 Feb., 02:30, Steven D'Aprano wrote: > Python lists are arrays of pointers to objects, so copying a slice is > fast: it doesn't have to copy the objects, just pointers. Deleting from > the end of the list is also quick, because you don't have to move memory, > just clear some pointers and cha

Efficient way to break up a list into two pieces

2010-02-20 Thread marwie
Hello, I recently read about augmented assignments and that (with l1, l2 being lists) l1.extend(l2) is more efficient than l1 = l1 + l2 because unnecessary copy operations can be avoided. Now my question is if there's a similar thing for breaking a list into two parts. Let's say I want