Specify start and length, beside start and end, in slices
Grant Edwards
grante at visi.com
Fri May 21 12:25:09 EDT 2004
On 2004-05-21, Noam Raphael <noamr at correctme.users.sourcephorge.net> wrote:
>>>> It's a bit less efficient, but you can currently spell that as
>>>>
>>>> l[12345:][:10]
>>>>
>>> That is true, but if the list is long, it's *much* less efficient.
>>
>> Considering that the interpreter special-cases some integer math
>> including the BINARY_ADD, it likely wouldn't take a very long list
>> to pass the point where they're the same.
I'm afraid I don't understand either. Where do integer math
shortcuts enter the picture? It seems to me it's all about
building a (possibly long new list) which you're going to throw
away after you build another list from the front it.
Unless the compiler is smart enough to figure out what you're
aiming at and skip the intermediate list entirely.
> I don't understand: If the list is of length 1000000, wouldn't
> Grant Edwards' suggestion make 1000000-12345 new references,
> and then take only the first ten of them?
Yes, according to my understanding of how things work, that's
what happens (my spelling is pretty inefficient for pulling
small chunks from the beginnings of long lists), so if you do
a lot of that, it may be worth worrying about.
--
Grant Edwards grante Yow! Civilization is
at fun! Anyway, it keeps
visi.com me busy!!
More information about the Python-list
mailing list