cas...@gmail.com wrote:
On Thursday, October 25, 2012 7:56:25 AM UTC-7, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an& operation)?
You may want to look at gmpy2[1] and the popcount() function.
Alternatively, is there any VERY li
On Thursday, October 25, 2012 7:56:25 AM UTC-7, Charles Hixson wrote:
> In Python3 is there any good way to count the number of on bits in an
> integer (after an & operation)?
You may want to look at gmpy2[1] and the popcount() function.
>
> Alternatively, is there any VERY light-weight impleme
On 2012-10-25, Ian Kelly wrote:
> On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti
> wrote:
>> Yes indeed! Python string operations are fast enough and its
>> arithmetic slow enough that I no longer assume I can beat a
>> neat lexicographical solution. Try defeating the following
>> with arithmetic:
On 25-10-12 16:47, Charles Hixson wrote:
> In Python3 is there any good way to count the number of on bits in an
> integer (after an & operation)?
> Alternatively, is there any VERY light-weight implementation of a bit
> set? I'd prefer to use integers, as I'm probably going to need
> thousands of
On Thu, 25 Oct 2012 14:20:00 -0600, Ian Kelly wrote:
> On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti wrote:
>> Yes indeed! Python string operations are fast enough and its arithmetic
>> slow enough that I no longer assume I can beat a neat lexicographical
>> solution. Try defeating the following
On 25/10/2012 17:08, Charles Hixson wrote:
On 10/25/2012 08:57 AM, Steven D'Aprano wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
wrote:
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count("1"
On 10/25/2012 08:57 AM, Steven D'Aprano wrote:
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
wrote:
Simple, easy, faster than a Python loop but not very elegant:
bin(number).count("1")
Unlikely to be fast.
Oh I don't know abo
On Thu, Oct 25, 2012 at 2:00 PM, Neil Cerutti wrote:
> Yes indeed! Python string operations are fast enough and its
> arithmetic slow enough that I no longer assume I can beat a neat
> lexicographical solution. Try defeating the following with
> arithmetic:
>
> def is_palindrom(n):
>s = str(n)
On 10/25/2012 12:13 PM, rusi wrote:
On Oct 25, 7:56 pm, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an & operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm prob
On 2012-10-25, Neil Cerutti wrote:
> Try defeating the following with arithmetic:
>
> def is_palindrom(n):
>s = str(n)
>return s = s[::-1]
Sorry for the typos. It should've been:
def is_palindrome(n):
s = str(n)
return s == s[::-1]
--
Neil Cerutti
--
http://mail.python.org/mailm
On 2012-10-25, Steven D'Aprano wrote:
> On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
>> On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
>>
>> wrote:
>>> Simple, easy, faster than a Python loop but not very elegant:
>>>
>>>bin(number).count("1")
>>
>> Unlikely to be fast.
>
> O
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=1, repeat=7)
On Thu, Oct 25, 2012 at 11:25 AM, Christian Gollwitzer wrote:
> There is a very geeky algorithm with only a few integer operations.
>
> Checkout
> http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSet64
>
> for a C version. Maybe the same thing is equally fast when ported to Python.
It
Am 25.10.12 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)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these
On Thu, 25 Oct 2012 09:17:40 -0700, rusi wrote:
> On Oct 25, 8:57 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote:
>> On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
>> > On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
>> > wrote:
>> >> Simple, easy, faster than a Python l
On Oct 25, 9:30 pm, Chris Angelico wrote:
> On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote:
> > On Oct 25, 8:57 pm, Steven D'Aprano > +comp.lang.pyt...@pearwood.info> wrote:
> >> py> min(t.repeat(number=1, repeat=7))
> >> 0.6819710731506348
> >> py> min(t.repeat(number=100, repeat=7))
> >> 4.14
On 25/10/2012 17:29, Chris Angelico wrote:
On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote:
On Oct 25, 8:57 pm, Steven D'Aprano wrote:
py> min(t.repeat(number=1, repeat=7))
0.6819710731506348
py> min(t.repeat(number=100, repeat=7))
4.141788959503174
That makes the "inelegant" solution using
On Thu, Oct 25, 2012 at 9:24 AM, Mark Lawrence wrote:
> On 25/10/2012 15:47, Charles Hixson wrote:
>
>> In Python3 is there any good way to count the number of on bits in an
>> integer (after an & operation)?
>> Alternatively, is there any VERY light-weight implementation of a bit
>> set? I'd pre
On Fri, Oct 26, 2012 at 3:17 AM, rusi wrote:
> On Oct 25, 8:57 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote:
>> py> min(t.repeat(number=1, repeat=7))
>> 0.6819710731506348
>> py> min(t.repeat(number=100, repeat=7))
>> 4.141788959503174
>>
>> That makes the "inelegant" solution u
On 25/10/2012 15:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an & operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these
On Oct 25, 8:57 pm, Steven D'Aprano wrote:
> On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
> > On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
> > wrote:
> >> Simple, easy, faster than a Python loop but not very elegant:
>
> >> bin(number).count("1")
>
> > Unlikely to be fast.
>
On Oct 25, 7:56 pm, Charles Hixson wrote:
> In Python3 is there any good way to count the number of on bits in an
> integer (after an & operation)?
> Alternatively, is there any VERY light-weight implementation of a bit
> set? I'd prefer to use integers, as I'm probably going to need
> thousands
On Fri, 26 Oct 2012 02:31:53 +1100, Chris Angelico wrote:
> On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes
> wrote:
>> Simple, easy, faster than a Python loop but not very elegant:
>>
>>bin(number).count("1")
>
> Unlikely to be fast.
Oh I don't know about that. Here's some timing results
On Fri, Oct 26, 2012 at 2:25 AM, Christian Heimes wrote:
> Simple, easy, faster than a Python loop but not very elegant:
>
>bin(number).count("1")
Unlikely to be fast.
What you may want is some sort of hybrid loop/lookup approach. Do you
know what your highest bit number is going to be? For
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
--
http://mail.python.org/mailman/listinfo/
On 2012-10-25 15:47, Charles Hixson wrote:
In Python3 is there any good way to count the number of on bits in an
integer (after an & operation)?
Alternatively, is there any VERY light-weight implementation of a bit
set? I'd prefer to use integers, as I'm probably going to need
thousands of these
26 matches
Mail list logo