how to break a for loop?

Jesus Rivero - (Neurogeek) jrivero at latinux.org
Mon Feb 20 19:57:13 EST 2006


-----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 zeros or just do something like this:

list_ = [0,0,0,1,0,0,1]
print [ elm for elm in list_ if elm != 0 ]
[1,1]



Regards,

Jesus (Neurogeek)

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:
>                 del coefs[i]
>             else:
>                 break
> 
> but it removes ALL zeros from list. What's up?
> 
> 
> P.S. I feel SO stupid asking this quastion... ;-)
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD+mVpdIssYB9vBoMRAl4hAJ9RnvgvEo5NsutG9KmD6qOEL7VyFgCfeLit
h7FLsbRvHR1z5DSxSPZHFlY=
=SY2U
-----END PGP SIGNATURE-----



More information about the Python-list mailing list