On Jul 8, 10:44 am, Daniel Austria <futureb...@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 -- http://mail.python.org/mailman/listinfo/python-list