Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19692

Re: Iterate from 2nd element of a huge list

References <jga54q$vqg$1@speranza.aioe.org> <jgaaqr$abr$1@speranza.aioe.org>
Date 2012-02-01 07:09 +0000
Subject Re: Iterate from 2nd element of a huge list
From Arnaud Delobelle <arnodel@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5288.1328080180.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 1 February 2012 03:16, Paulo da Silva <p_s_d_a_s_i_l_v_a@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Iterate from 2nd element of a huge list Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-02-01 01:39 +0000
  Re: Iterate from 2nd element of a huge list Cameron Simpson <cs@zip.com.au> - 2012-02-01 13:02 +1100
  Re: Iterate from 2nd element of a huge list duncan smith <buzzard@urubu.freeserve.co.uk> - 2012-02-01 02:31 +0000
  Re: Iterate from 2nd element of a huge list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-01 02:43 +0000
  Re: Iterate from 2nd element of a huge list Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-02-01 03:16 +0000
    Re: Iterate from 2nd element of a huge list Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-02-01 03:34 +0000
      Re: Iterate from 2nd element of a huge list Cameron Simpson <cs@zip.com.au> - 2012-02-01 15:55 +1100
        Re: Iterate from 2nd element of a huge list Paulo da Silva <p_s_d_a_s_i_l_v_a@netcabo.pt> - 2012-02-02 07:23 +0000
          Re: Iterate from 2nd element of a huge list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 07:38 +0000
    Re: Iterate from 2nd element of a huge list Arnaud Delobelle <arnodel@gmail.com> - 2012-02-01 07:09 +0000
    Re: Iterate from 2nd element of a huge list Peter Otten <__peter__@web.de> - 2012-02-01 09:11 +0100
    Re: Iterate from 2nd element of a huge list Arnaud Delobelle <arnodel@gmail.com> - 2012-02-01 10:54 +0000
  Re: Iterate from 2nd element of a huge list Paul Rubin <no.email@nospam.invalid> - 2012-02-01 01:25 -0800
    Re: Iterate from 2nd element of a huge list Stefan Behnel <stefan_ml@behnel.de> - 2012-02-01 12:28 +0100

csiph-web