bit count or bit set && Python3

Serhiy Storchaka storchaka at gmail.com
Thu Oct 25 15:07:45 EDT 2012


Chris Angelico's suggestion:

 >>> bitcount = bytes(bin(i).count("1") for i in range(256))
 >>> t = Timer('sum(number.to_bytes((number.bit_length() + 7) // 8,'
... '"little").translate(bitcount))',
... setup='from __main__ import bitcount; number=2**10001-1')
 >>> min(t.repeat(number=10000, repeat=7))





More information about the Python-list mailing list