On 1 February 2012 12:39, Paulo da Silva <p_s_d_a_s_i_l_...@netcabo.pt>wrote:

> 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?
>

If you are sure that mylist contains at least one element:

>>> mylist = [1, 2, 3]
>>> i = iter(mylist)
>>> print next(i)
1
>>> for el in i:
...     print el
...
2
3

Note: for older pythons, you may need i.next() instead of next(i).

If mylist may be empty, you will need some error handling.

Tim Delaney
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to