Re: ... remove all 0 values

2009-07-09 Thread Daniel Austria
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Stefan Behnel
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Paul Rubin
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

Re: ... remove all 0 values

2009-07-08 Thread Simon Forman
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 &

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Friðrik Már Jónsson
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread J Kenneth King
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Diez B. Roggisch
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.

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Friðrik Már Jónsson
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread D'Arcy J.M. Cain
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. --

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Charles Yeomans
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Bruno Desthuilliers
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

Re: [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread ma
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

[0, 0, 0, 1, 1, 1, 0] ... remove all 0 values

2009-07-08 Thread Daniel Austria
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