>>>> b = numpy.zeros(10**7, dtype=bool)
>>>> for x in 3, 4, 6: b[10**x] = True
> ...
>>>> b.sum()
> 3

Without numpy:

>>> counts = [bin(i).count('1') for i in range(256)]
>>> bytes = b"hello python"*100000
>>> len(bytes)*8
9600000
>>> sum(map(counts.__getitem__, bytes))
4800000

Pretty fast as well.

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to