Simple newbie question
Dang Griffith
noemail at noemail4u.com
Fri Dec 5 07:44:38 EST 2003
On Thu, 4 Dec 2003 15:36:11 +0100, Angelo Secchi <secchi at sssup.it>
wrote:
>I'm trying to remove lines with zeros from a list "lista".
>The code i'm using is the following:
>
>for line in lista:
> if sum(line == 0) > 0:
> lista.remove(line)
>
>
>The problem is that the loop stops at the first line with zeros and it
>doesn't remove the other lines with zeros (at least if I do not re-run
>the loop). Probably I do not understand how the loop works.
I see other's responses, but am wondering why the line
if sum(line == 0) > 0:
doesn't raise a "TypeError: iteration over non-sequence" for everyone
else. line==0 is a single boolean, and a sum on that raises an
exception for me.
I'm also wondering why the program compiles, since the
lista.remove(line)
should be more indented.
Thanks,
--dang
More information about the Python-list
mailing list