Iterate from 2nd element of a huge list

Paulo da Silva p_s_d_a_s_i_l_v_a at netcabo.pt
Thu Feb 2 02:23:04 EST 2012


Em 01-02-2012 04:55, Cameron Simpson escreveu:
> On 01Feb2012 03:34, Paulo da Silva <p_s_d_a_s_i_l_v_a at netcabo.pt> 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 differences were almost
always consistent.

I put mylist1=mylist[1:] outside the time control. iter still seems a
little bit faster. Running both programs several times (10000000
elements list) I only got iter being slower once!

But, of course, most of the difference comes from the copy.



More information about the Python-list mailing list