Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32133

Re: bit count or bit set && Python3

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1351178764; bh=otHZPZy44PiLMg7j3YaP+AiUc9/Oi5S+Q2+rWDvZS4Q=; h=To:From:Subject:Date:Message-ID:References:Mime-Version: Content-Type:Content-Transfer-Encoding:In-Reply-To; b=UrJNlHuH+1fK7JL7Zs62tSbybMrSoPTjnHECkJEA6loNZs8dBVCS8/nb30G1kzi7A 6I/GejcmSl5suuaWAIL/2Vke6/fVDGHOC+NkFb+Yt4XVeaoE8KIFsoLm3u/rKn3BmL C9a7WMedzWUlIt2PhQlro4SukJW6ib1SjpCAoNsY=
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python3': 0.05; 'bits': 0.07; 'python': 0.09; '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; 'from:name:christian heimes': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:bit': 0.16; 'from:addr:python.org': 0.17; 'integer': 0.17; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.28; 'to:addr:python-list': 0.33; 'skip:b 20': 0.34; 'christian': 0.34; 'faster': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Christian Heimes <christian@python.org>
Subject Re: bit count or bit set && Python3
Date Thu, 25 Oct 2012 17:25:47 +0200
References <5089511E.4090009@earthlink.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host smtp.semantics.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
In-Reply-To <5089511E.4090009@earthlink.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2848.1351178765.27098.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351178765 news.xs4all.nl 6925 [2001:888:2000:d::a6]:39487
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32133

Show key headers only | View raw


Am 25.10.2012 16:47, schrieb Charles Hixson:
> In Python3 is there any good way to count the number of on bits in an
> integer (after an & operation)?


Simple, easy, faster than a Python loop but not very elegant:

   bin(number).count("1")

Christian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: bit count or bit set && Python3 Christian Heimes <christian@python.org> - 2012-10-25 17:25 +0200

csiph-web