> 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: > groups.append(seq[start:stop]) > start = stop > groups.append(seq[start:]) > return groups
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: if seq[stop] & 0x80: push(seq[start:stop]) start = stop push(seq[start:]) return groups -Matt -- http://mail.python.org/mailman/listinfo/python-list