Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Steven D'Aprano
On Thu, 02 Feb 2012 07:23:04 +, Paulo da Silva wrote: > Em 01-02-2012 04:55, Cameron Simpson escreveu: >> On 01Feb2012 03:34, Paulo da Silva >> wrote: > >> | BTW, iter seems faster than iterating thru mylist[1:]! >> >> I would hope the difference can be attributed to the cost of copying >>

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Paulo da Silva
Em 01-02-2012 04:55, Cameron Simpson escreveu: > On 01Feb2012 03:34, Paulo da Silva wrote: > | BTW, iter seems faster than iterating thru mylist[1:]! > > I would hope the difference can be attributed to the cost of copying > mylist[1:]. I don't think so. I tried several times and the difference

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Stefan Behnel
Paul Rubin, 01.02.2012 10:25: > Paulo da Silva writes: >> process1(mylist[0]) >> for el in mylist[1:]: >> process2(el) >> >> This way mylist is almost duplicated, isn't it? > > I think it's cleanest to use itertools.islice to get the big sublist > (not tested): > >from itertools import i

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Arnaud Delobelle
On 1 February 2012 08:11, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > The example should be > >> from itertools import islice: > > for el in islice(mylist, 1, None): >>     process2(el) Oops! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Paul Rubin
Paulo da Silva writes: > process1(mylist[0]) > for el in mylist[1:]: > process2(el) > > This way mylist is almost duplicated, isn't it? I think it's cleanest to use itertools.islice to get the big sublist (not tested): from itertools import islice process1 (mylist[0]) for el in i

Re: Iterate from 2nd element of a huge list

2012-02-01 Thread Peter Otten
Arnaud Delobelle wrote: >> Em 01-02-2012 01:39, Paulo da Silva escreveu: >>> What is the best way to iterate thru a huge list having the 1st element >>> a different process? I.e.: > Nobody mentioned itertools.islice, which can be handy, especially if > you weren't interested in the first element

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Arnaud Delobelle
On 1 February 2012 03:16, Paulo da Silva 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

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Cameron Simpson
On 01Feb2012 03:34, Paulo da Silva wrote: | Em 01-02-2012 03:16, Paulo da Silva escreveu: | > I think iter is nice for what I need. | > Thank you very much to all who responded. | | BTW, iter seems faster than iterating thru mylist[1:]! I would hope the difference can be attributed to the cost o

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Paulo da Silva
Em 01-02-2012 03:16, Paulo da Silva escreveu: > 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 myl

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Paulo da Silva
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 t

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread duncan smith
On 01/02/12 01:39, Paulo da Silva 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? Thanks. Maybe (untested), it = iter

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Tim Delaney
On 1 February 2012 12:39, Paulo da Silva 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 sur

Re: Iterate from 2nd element of a huge list

2012-01-31 Thread Cameron Simpson
On 01Feb2012 01:39, Paulo da Silva wrote: | 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? Yep. What about (untested):