Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Python3': 0.09; 'subject:set': 0.09; "skip:' 30": 0.15; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:bit': 0.16; '>>>': 0.18; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; 'to:addr:python-list': 0.33; 'skip:b 20': 0.34; 'received:org': 0.36; 'skip:t 40': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'skip:n 10': 0.63 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: bit count or bit set && Python3 Date: Thu, 25 Oct 2012 22:07:45 +0300 References: <5089511E.4090009@earthlink.net> <50896152$0$29978$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 37.115.66.25 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120912 Thunderbird/15.0.1 In-Reply-To: <50896152$0$29978$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 9 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351192087 news.xs4all.nl 6972 [2001:888:2000:d::a6]:54520 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32155 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))