... remove all 0 values
Simon Forman
sajmikins at gmail.com
Wed Jul 8 14:01:28 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, 10:44 am, Daniel Austria <futureb... 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
If you are doing something like this:
L = [0, 0, 0, 1, 1, 1, 0]
removeZeros(L)
number_of_ones = len(L)
you can just use sum() like so:
number_of_ones = sum(L)
HTH
- 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