En Tue, 06 Mar 2007 17:07:45 -0300, Matthias Julius <[EMAIL PROTECTED]>
escribió:
> "Gabriel Genellina" <[EMAIL PROTECTED]> writes:
>
>> Dictionary access is highly optimized in Python. In fact, using a
>> precomputed dictionary is about 12 times faster:
>
> Why using a dictionary and not a list
"Gabriel Genellina" <[EMAIL PROTECTED]> writes:
> En Fri, 02 Mar 2007 08:22:36 -0300, Bart Ogryczak
> <[EMAIL PROTECTED]> escribió:
>
>> On Mar 1, 7:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
>> wrote:
>>> Thanks Bart. That's perfect. The other suggestion was to precompute
>>> count1 for all
"Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> On Mar 5, 10:51 am, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> > > "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
> > >BO> Any system with 8-bit bytes, which would mean any system made after
> > >BO> 1965. I'm not aware of any Python implement
"Piet van Oostrum" <[EMAIL PROTECTED]> wrote:
> > "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
>
> >BO> Any system with 8-bit bytes, which would mean any system made after
> >BO> 1965. I'm not aware of any Python implementation for UNIVAC, so I
> >BO> wouldn't worry ;-)
>
> 1965? I worked
En Fri, 02 Mar 2007 08:22:36 -0300, Bart Ogryczak <[EMAIL PROTECTED]>
escribió:
> On Mar 1, 7:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>> Thanks Bart. That's perfect. The other suggestion was to precompute
>> count1 for all possible bytes, I guess that's 0-256, right?
>
> 0-255
On Mar 5, 10:51 am, Piet van Oostrum <[EMAIL PROTECTED]> wrote:
> > "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
> >BO> Any system with 8-bit bytes, which would mean any system made after
> >BO> 1965. I'm not aware of any Python implementation for UNIVAC, so I
> >BO> wouldn't worry ;-)
>
> 1
> "Bart Ogryczak" <[EMAIL PROTECTED]> (BO) wrote:
>BO> Any system with 8-bit bytes, which would mean any system made after
>BO> 1965. I'm not aware of any Python implementation for UNIVAC, so I
>BO> wouldn't worry ;-)
1965? I worked with non-8-byte machines (CDC) until the beginning of the
80
On Mar 1, 7:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Mar 1, 12:46 pm, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> > > This solution looks nice, but how does it work? I'm guessing
> > > struct.unpack will provide me with 8 bit bytes
>
> > unpack with 'B' format gives you int val
<[EMAIL PROTECTED]> wrote:
> Thanks Bart. That's perfect. The other suggestion was to precompute
> count1 for all possible bytes, I guess that's 0-256, right?
0 to 255 inclusive, actually - that is 256 numbers...
The largest number representable in a byte is 255
eight bits, of value 128,64,32
On Mar 1, 12:46 pm, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> > This solution looks nice, but how does it work? I'm guessing
> > struct.unpack will provide me with 8 bit bytes
>
> unpack with 'B' format gives you int value equivalent to unsigned char
> (1 byte).
>
> > (will this work on any sys
On Mar 1, 4:58 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Mar 1, 8:53 am, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mar 1, 7:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
>
> > > It seems like this would be easy but I'm drawing a blank.
>
> > > What I want to
On Mar 2, 12:53 am, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
>
> import struct
> buf = open('somefile','rb').read()
> count1 = lambda x: (x&1)+(x&2>0)+(x&4>0)+(x&8>0)+(x&16>0)+(x&32>0)+
> (x&64>0)+(x&128>0)
> byteOnes = map(count1,struct.unpack('B'*len(buf),buf))
byteOnes = map(count1,struct.unp
On Mar 1, 8:53 am, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> On Mar 1, 7:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > It seems like this would be easy but I'm drawing a blank.
>
> > What I want to do is be able to open any file in binary mode, and read
> > in one byte (8 bits) a
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)
Bart Ogryczak kirjoitti:
> On Mar 1, 7:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>> It seems like this would be easy but I'm drawing a blank.
>>
>> What I want to do is be able to open any file in binary mode, and read
>> in one byte (8 bits) at a time and then count the number of 1 b
On Mar 1, 7:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> It seems like this would be easy but I'm drawing a blank.
>
> What I want to do is be able to open any file in binary mode, and read
> in one byte (8 bits) at a time and then count the number of 1 bits in
> that byte.
>
> I got as
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)]
--
http://mail.python.org/mailman/listin
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> It seems like this would be easy but I'm drawing a blank.
>
> What I want to do is be able to open any file in binary mode, and read
> in one byte (8 bits) at a time and then count the number of 1 bits in
> that byte.
>
> I got as far as this but it
It seems like this would be easy but I'm drawing a blank.
What I want to do is be able to open any file in binary mode, and read
in one byte (8 bits) at a time and then count the number of 1 bits in
that byte.
I got as far as this but it is giving me strings and I'm not sure how
to accurately get
19 matches
Mail list logo