Efficiently iterating over part of a list
Ziga Seilnacht
ziga.seilnacht at gmail.com
Fri Oct 13 04:02:57 EDT 2006
Steven D'Aprano wrote:
[snip]
> The important thing to notice is that alist[1:] makes a copy. What if the
> list has millions of items and duplicating it is expensive? What do people
> do in that case?
>
> Are there better or more Pythonic alternatives to this obvious C-like
> idiom?
>
> for i in range(1, len(alist)):
> x = alist[i]
for x in itertools.islice(alist, 1, len(alist)):
HTH
Ziga
More information about the Python-list
mailing list