N
Nick Forest
Any body knows a trivial way to enumerate a list with n zero-valued elements?
Nick said:Any body knows a trivial way to enumerate a list with n zero-valued
elements?
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])
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.