Efficient way to break up a list into two pieces

Jonathan Gardner jgardner at jonathangardner.net
Mon Feb 22 00:15:43 EST 2010


On Sat, Feb 20, 2010 at 10:48 PM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote:
>> 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.
>
> My mistake, he actually wants l1[10:] copied. So you might be copying a
> huge amount of data, not just ten items.
>
> Or if you prefer, replace 10 by 100000000.
>

If you need to scale that direction, it's time to install a database.

>> 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.
>
> You missed the point that your suggestion gives radically different
> behaviour to what the OP indicated he is using. He mutates the list in
> place, you rebind the list's name. That has *very* different semantics.
>
>
> The OP may not care about the difference, but if he does require the
> first behaviour, then your solution doesn't help.
>

Correct.

-- 
Jonathan Gardner
jgardner at jonathangardner.net



More information about the Python-list mailing list