Matimus wrote:
> Excellent work! One more modification and I get below 10us/pass:
>
> def getgroups(seq):
> groups = []
> push = groups.append
> iseq = iter(xrange(len(seq)))
> for start in iseq:
> if seq[start] & 0x80:
> for stop in iseq:
>
> A little renaming of variables helps it be a bit more elegant I think ...
>
> def getgroups8(seq):
> groups = []
> iseq = iter(xrange(len(seq)))
> for start in iseq:
> if seq[start] & 0x80:
> for stop in iseq:
> if seq[stop] & 0x80:
>
On Jul 17, 1:48 pm, Matimus <[EMAIL PROTECTED]> wrote:
> I did some more experimenting and came up with the code below. It
> shows several methods. When run, the script tests the robustness of
> each method (roughly), and profiles it using timeit. The results from
> running on my laptop are shown b
Hello Dan,
Yet another option (using itertools.groupby):
from itertools import groupby
class GrouperToggler:
def __init__(self):
self.group = 1
def __call__(self, value):
# New packet, toggle group
if value & 0x80:
self.group = 1 - self.group
Matt McCredie wrote:
> That certainly is fast, unfortunately it doesn't pass all of the tests.
> I came up with those tests so I don't know how important they are to the
> original poster. I modified it and came up with a generator and a
> non-generator version based (roughly) on your algorith
That certainly is fast, unfortunately it doesn't pass all of the tests. I
came up with those tests so I don't know how important they are to the
original poster. I modified it and came up with a generator and a
non-generator version based (roughly) on your algorithm, that are almost as
quick, and
Matimus wrote:
> I did some more experimenting and came up with the code below. It
> shows several methods. When run, the script tests the robustness of
> each method (roughly), and profiles it using timeit. The results from
> running on my laptop are shown below the code.
Try this one...
def g
I did some more experimenting and came up with the code below. It
shows several methods. When run, the script tests the robustness of
each method (roughly), and profiles it using timeit. The results from
running on my laptop are shown below the code.
seqs = [# Original:
[0xF0, 1, 2, 3, 0
Paul Rubin wrote:
> See:
>
> http://groups.google.com/group/comp.lang.python/msg/2410c95c7f3b3654
Groupby is damn slow as far as I can tell (the Bates numbering in the
above link assumes more than the OP intended, I assume). It looks like
the author's original algorithm is the fastest python wa
> Here's an ugly way I wouldn't recommended (using itertools groupby):
>
> py> from itertools import groupby
> py> alist = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6,
> ... 0xF1, 7, 8, 0xF2, 9, 10, 11, 12, 13,
> ... 0xF0, 14, 0xF1, 15]
> py> def doit(alist):
> ... i = (list(g) for k,g in gro
On Jul 16, 3:56 pm, marduk <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-07-16 at 16:31 -0500, marduk wrote:
> > Assuming you meant '0xF0' instead of '0x80' do you mean any value
> > >=240 starts a new group? If so:
No, I meant 0x80. 0x80 is only the most significant bit of the 0xF0
value. Every t
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
>
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
>
> A value with
This is a perfect place for a generator:
seq = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
13, 0xF0, 14, 0xF1, 15]
def gengroups(seq):
group = []
for val in seq:
if val & 0x80 and group:
yield group
group = []
group.append(val)
James Stroud wrote:
> Here's how I *would* do it:
>
> py> def doit(alist):
> ... ary = []
> ... for i in alist:
> ... if 0xf0 & i:
> ... ary.append([i])
> ... else:
> ... ary[-1].append(i)
> ... return [x for x in ary if x]
> ...
To be absolutely compliant with the spec
[EMAIL PROTECTED] wrote:
> All,
>
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
>
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
>
> A value with bit 0x80 set
On Mon, 2007-07-16 at 16:31 -0500, marduk wrote:
> Assuming you meant '0xF0' instead of '0x80' do you mean any value
> >=240 starts a new group? If so:
>
> groups = []
> current = [] # probably not necessary, but as a safety
> for i in l:
> if i >= 240:
> current = []
> gr
On Mon, 2007-07-16 at 14:11 -0700, [EMAIL PROTECTED] wrote:
> I can't seem to find an answer to this question anywhere, but I'm
> still looking. My problem is I have a list of values like this:
>
> l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
> 13, 0xF0, 14, 0xF1, 15]
>
> A
All,
I can't seem to find an answer to this question anywhere, but I'm
still looking. My problem is I have a list of values like this:
l = [0xF0, 1, 2, 3, 0xF0, 4, 5, 6, 0xF1, 7, 8, 0xF2, 9, 10, 11, 12,
13, 0xF0, 14, 0xF1, 15]
A value with bit 0x80 set delineates the start of a new packet of
inf
18 matches
Mail list logo