Iterate from 2nd element of a huge list
Arnaud Delobelle
arnodel at gmail.com
Wed Feb 1 02:09:35 EST 2012
On 1 February 2012 03:16, Paulo da Silva <p_s_d_a_s_i_l_v_a at netcabo.pt> wrote:
> Em 01-02-2012 01:39, Paulo da Silva escreveu:
>> Hi!
>>
>> What is the best way to iterate thru a huge list having the 1st element
>> a different process? I.e.:
>>
>> process1(mylist[0])
>> for el in mylist[1:]:
>> process2(el)
>>
>> This way mylist is almost duplicated, isn't it?
>>
>> Thanks.
>
>
> I think iter is nice for what I need.
> Thank you very much to all who responded.
Nobody mentioned itertools.islice, which can be handy, especially if
you weren't interested in the first element of the list:
from itertools import islice:
for el in islice(mylist, 1):
process2(el)
--
Arnaud
More information about the Python-list
mailing list