[0, 0, 0, 1, 1, 1, 0] ... remove all 0 values
Charles Yeomans
charles at declareSub.com
Wed Jul 8 11:02:16 EDT 2009
- Previous message (by thread): [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values
- Next message (by thread): [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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 <futurebase at gmx.at>
> 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
> raised is also uncool, right?
>
> Some suggestions?
>
L = [0, 0, 0, 1, 1, 1, 0]
M = [x for x in L if x !=0]
Charles Yeomans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090708/3e9ee60c/attachment-0001.html>
- Previous message (by thread): [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values
- Next message (by thread): [0, 0, 0, 1, 1, 1, 0] ... remove all 0 values
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Python-list
mailing list