lists with zero-valued elements
Skip Montanaro
skip at pobox.com
Sat Dec 27 16:52:22 EST 2003
More information about the Python-list mailing list
Sat Dec 27 16:52:22 EST 2003
- Previous message (by thread): Chandler status (was Re: Project dream
- Next message (by thread): lists with zero-valued elements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick> Any body knows a trivial way to enumerate a list with n
Nick> zero-valued elements?
I'm not sure what you're asking. I'd enumerate a list with n zero-valued
elements the same way I'd enumerate one with m zero-valued elements:
nelements = len(somelist)
If I wanted to count how many elements were zero, I might do something like:
nzeros = 0
for element in somelist:
if element == 0:
nzeros += 1
or more succinctly:
nzeros = len([element for element in somelist if element == 0])
Skip
- Previous message (by thread): Chandler status (was Re: Project dream
- Next message (by thread): lists with zero-valued elements
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list