Thanks a lot for your advices,
i decided to use the filter() method to sort out the 0.
i can ´t use the sum() function cause i need the list afterwards
best,
Dan
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin wrote:
> Daniel Austria writes:
>> just one question. How can i remove all 0 values in a list?
>
> I prefer:
>
>newlist = list(x for x in oldlist if x != 0)
>
> to the square bracket list comprehension that a few people have
> suggested. This
Daniel Austria writes:
> just one question. How can i remove all 0 values in a list?
I prefer:
newlist = list(x for x in oldlist if x != 0)
to the square bracket list comprehension that a few people have
suggested. This is because in python 2.x, the listcomp "leaks" its
i
On Jul 8, 10:44 am, Daniel Austria wrote:
> Hi python - hackers,
>
> just one question. How can i remove all 0 values in a list? Sure - i
> can loop over it, but that s not a neat style. list.remove() will
> only remove the first occurence. Doing that while no exception is
&
J Kenneth King wrote:
I was wondering when someone would mention filter()
I was happy to see that too.
It's clean, faster than list comprehension and in terms of clarity
it's only to be expected that the developer is familiar with, or at
least willing to look up, the available built-in met
Friðrik Már Jónsson writes:
> ma wrote:
>> filter(lambda x: x, your_list)
>
> Good call! Equivalent but more efficient:
>
> filter(None, your_list)
>
> Regards,
> Friðrik Már
I was wondering when someone would mention filter()
--
http://mail.python.org/mailman/listinfo/python-list
Daniel Austria wrote:
> Hi python - hackers,
>
> just one question. How can i remove all 0 values in a list? Sure - i
> can loop over it, but that s not a neat style.
Why not? If you need to potentially look at *all* elements of a list,
nothing but a loop will take you there.
ma wrote:
filter(lambda x: x, your_list)
Good call! Equivalent but more efficient:
filter(None, your_list)
Regards,
Friðrik Már
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 8 Jul 2009 10:54:09 -0400
ma wrote:
> filter(lambda x: x, your_list)
Or...
[x for x in your_list if x]
I'm not sure which one is more efficient but I like the syntax of the
latter. A smart person could probably figure it out even without
knowing Python syntax. Clarity is trump.
--
On Jul 8, 2009, at 10:54 AM, ma wrote:
filter(lambda x: x, your_list)
On Wed, Jul 8, 2009 at 10:44 AM, Daniel Austria
wrote:
Hi python - hackers,
just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style. list.remove() will
only
Daniel Austria a écrit :
Hi python - hackers,
just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style. list.remove() will
only remove the first occurence. Doing that while no exception is
raised is also uncool, right?
Some suggestions
filter(lambda x: x, your_list)
On Wed, Jul 8, 2009 at 10:44 AM, Daniel Austria wrote:
> Hi python - hackers,
>
> just one question. How can i remove all 0 values in a list? Sure - i
> can loop over it, but that s not a neat style. list.remove() will
> only remove the first o
Hi python - hackers,
just one question. How can i remove all 0 values in a list? Sure - i
can loop over it, but that s not a neat style. list.remove() will
only remove the first occurence. Doing that while no exception is
raised is also uncool, right?
Some suggestions?
Best,
Dan
--
http
13 matches
Mail list logo