counting occurances in lists within lists.

Cliff Wells LogiplexSoftware at earthlink.net
Sat Dec 21 12:49:03 EST 2002


On Sat, 2002-12-21 at 09:35, Adonis wrote:
> how do i effectively count the amount of 0s in what is mentioned on the
> subject.
> i.e.
> [[0,0,0,1,2,3]
>  [4,5,6,7,8,9]
>  [10,11,12,13,14,15]]
> 
> return 3 0s found.

numbers = [[0,0,0,1,2,3],[4,5,6,7,8,9],[10,11,12,13,14,15]]
reduce(int.__add__, [l.count(0) for l in numbers])


Regards,

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308





More information about the Python-list mailing list