Re: how to break a for loop?

2006-02-21 Thread bonono
[EMAIL PROTECTED] wrote: > This time it seems that using itertools gives slower results, this is > the test code: Understandable, as dropwhile still needs to go through the whole list and the difference will be larger when the list get longer. Though I still prefer that if the list is not horribly

Re: how to break a for loop?

2006-02-21 Thread bearophileHUGS
This time it seems that using itertools gives slower results, this is the test code: import itertools as it from operator import __not__ def trim_leading_zeros(seq): if not seq: return seq for pos, el in enumerate(seq): if el != 0: break if seq[pos] == 0:

Re: how to break a for loop?

2006-02-21 Thread Gregory Petrosyan
Thanks to everybody for help. Python community is very friendly and helpfull indeed! -- http://mail.python.org/mailman/listinfo/python-list

Re: how to break a for loop?

2006-02-21 Thread bonono
Giovanni Bajo wrote: > [EMAIL PROTECTED] wrote: > > >> I need to remove zeros from > >> the begining of list, but I can't :-(. > > > > I believe the following is almost a direct translation of the above > > sentence. > > > > import itertools as it > > a=[0,0,0,1,0] > > a[:]=it.dropwhile(lambda x:

Re: how to break a for loop?

2006-02-21 Thread Giovanni Bajo
[EMAIL PROTECTED] wrote: >> I need to remove zeros from >> the begining of list, but I can't :-(. > > I believe the following is almost a direct translation of the above > sentence. > > import itertools as it > a=[0,0,0,1,0] > a[:]=it.dropwhile(lambda x: x is 0, a) Usa lambda x: x==0 or simply l

Re: how to break a for loop?

2006-02-21 Thread Steven D'Aprano
Petr Jakes wrote: > zero_list=[0,0,0,0,0,1,2,3,4] > for x in range(len(zero_list)): > if zero_list[x]!=0: break > nonzero_list=zero_list[x:] > print nonzero_list > > but some more "pythonic" solutions will be posted from other users I > guess :) That looks perfectly Pythonic to me. You kno

Re: how to break a for loop?

2006-02-20 Thread bonono
Gregory Petrosyan wrote: >I need to remove zeros from > the begining of list, but I can't :-(. I believe the following is almost a direct translation of the above sentence. import itertools as it a=[0,0,0,1,0] a[:]=it.dropwhile(lambda x: x is 0, a) -- http://mail.python.org/mailman/listinfo/py

Re: how to break a for loop?

2006-02-20 Thread Scott David Daniels
Gregory Petrosyan wrote: > Hello! > It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe > that's why I encountered stupid problem: I need to remove zeros from > the begining of list, but I can't :-(. I use > > for i,coef in enumerate(coefs): > if coef == 0:

Re: how to break a for loop?

2006-02-20 Thread Jesus Rivero - (Neurogeek)
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello Gregory! I would also use lists to implement this. They are more practical and you could take advantage of pop() or remove() methods instead of using the Oh-so-Scary del. You could also use a lambda+map or reduce methods to remove all ze

Re: how to break a for loop?

2006-02-20 Thread Petr Jakes
zero_list=[0,0,0,0,0,1,2,3,4] for x in range(len(zero_list)): if zero_list[x]!=0: break nonzero_list=zero_list[x:] print nonzero_list but some more "pythonic" solutions will be posted from other users I guess :) HTH Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list

Re: how to break a for loop?

2006-02-20 Thread Schüle Daniel
Gregory Petrosyan wrote: > Hello! > It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe > that's why I encountered stupid problem: I need to remove zeros from > the begining of list, but I can't :-(. I use > > for i,coef in enumerate(coefs): > if coef == 0:

how to break a for loop?

2006-02-20 Thread Gregory Petrosyan
Hello! It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe that's why I encountered stupid problem: I need to remove zeros from the begining of list, but I can't :-(. I use for i,coef in enumerate(coefs): if coef == 0: del coefs[i]