[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
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:
Thanks to everybody for help. Python community is very friendly and
helpfull indeed!
--
http://mail.python.org/mailman/listinfo/python-list
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:
[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
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
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
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:
-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
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
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:
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]
12 matches
Mail list logo