Leif K-Brooks <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
> > You should probaby prepare before the loop a mapping from char to number
> > of 1 bits in that char:
> >
> > m = {}
> > for c in range(256):
> > m[c] = countones(c)
>
> Wouldn't a list be more efficient?
>
> m = [countones(c) for c in xrange(256)]
Yes, or an array.array -- actually I meant to use m[chr(c)] above (so
you could use the character you're reading directly to index m, rather
than calling ord(byte) a bazillion times for each byte you're reading),
but if you're using the numbers (as I did before) a list or array is
better.
Alex
--
http://mail.python.org/mailman/listinfo/python-list