Iterate from 2nd element of a huge list
timothy.c.delaney at gmail.com
Wed Feb 1 03:16:20 CET 2012
On 1 February 2012 12:39, Paulo da Silva <p_s_d_a_s_i_l_v_a at netcabo.pt>wrote:
> What is the best way to iterate thru a huge list having the 1st element
> a different process? I.e.:
> for el in mylist[1:]:
> 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)
>>> for el in i:
... print el
Note: for older pythons, you may need i.next() instead of next(i).
If mylist may be empty, you will need some error handling.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list