Efficient way to break up a list into two pieces

Jonathan Gardner jgardner at jonathangardner.net
Sun Feb 21 00:21:47 EST 2010


On Sat, Feb 20, 2010 at 5:41 PM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
>
> What the OP wants is:
>
> (1) assign the name l2 to l1[:10] without copying
> (2) resize l1 in place to the first 10 items without affecting l2.
>

For ten items, though, is it really faster to muck around with array
lengths than just copying the data over? Array copies are extremely
fast on modern processors.

Programmer time and processor time being what it is, I still think my
answer is the correct one. No, it's not what he says he wants, but it
is what he needs.

-- 
Jonathan Gardner
jgardner at jonathangardner.net



More information about the Python-list mailing list