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

ma mabdelkader at gmail.com
Wed Jul 8 10:54:09 EDT 2009


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?
>
>
> Best,
> Dan
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090708/f2433031/attachment-0001.html>


More information about the Python-list mailing list